TRT
Sign in

Caching and Routing Change the Request Path

A cache stores reusable results near the request path to reduce repeated work or latency. A cache-aside flow checks the cache, loads from the source on a miss, then stores the result with an expiry.

The Runtime Theory Team05 stages

trace / request.md

CONTRACTREPRESENTATIONOPERATIONBOUNDARYRESULT

readyA cache stores reusable results near the request path to reduce repeated work or latency. Routing decides which server or shard handles a request. Together they affect freshness, locality, load distribution, and which layer is responsible for serving a particular version of data.

Walk the stages in order for Caching and Routing Change the Request Path: start from the contract, trace the representation through the operation, then confirm the boundary. Worked case: A cache-aside flow checks the cache, loads from the source on a miss, then stores the result with an expiry. For a worked explanation, continue to the topic article and execution trace.

Stage-by-stage execution walkthrough

This request flow decomposes Caching and Routing Change the Request Path into 5 sequential stages so you can trace where latency accumulates, which state transitions are irreversible, and where production failure modes occur.

Stage 1: Contract

A cache stores reusable results near the request path to reduce repeated work or latency. Routing decides which server or shard handles a request. Together they affect freshness, locality, load distribution, and which layer is responsible for serving a particular version of data. During this transition, the runtime enforces strict state invariants before handing control to the next stage: inputs are validated at the boundary, state mutations are ordered deterministically, and latency/resource costs are bounded so downstream consumers never observe a torn or partially initialized state.

Stage 2: Representation

A cache-aside flow checks the cache, loads from the source on a miss, then stores the result with an expiry. A load balancer can distribute new connections among healthy backends, while consistent hashing can reduce key movement when a cache node changes. During this transition, the runtime enforces strict state invariants before handing control to the next stage: inputs are validated at the boundary, state mutations are ordered deterministically, and latency/resource costs are bounded so downstream consumers never observe a torn or partially initialized state.

Stage 3: Operation

A user updates a profile and immediately sees stale data from a cache. Compare expiry-only, explicit invalidation, and versioned cache keys for this consistency requirement. During this transition, the runtime enforces strict state invariants before handing control to the next stage: inputs are validated at the boundary, state mutations are ordered deterministically, and latency/resource costs are bounded so downstream consumers never observe a torn or partially initialized state.

Stage 4: Boundary

Invalidation is difficult because writes and cache fills can race. Sticky routing may improve locality but make failover and uneven load harder. Cache keys must include every input that changes the result, especially tenant, locale, authorization, and version context. During this transition, the runtime enforces strict state invariants before handing control to the next stage: inputs are validated at the boundary, state mutations are ordered deterministically, and latency/resource costs are bounded so downstream consumers never observe a torn or partially initialized state.

Stage 5: Result

A user updates a profile and immediately sees stale data from a cache. Compare expiry-only, explicit invalidation, and versioned cache keys for this consistency requirement. During this transition, the runtime enforces strict state invariants before handing control to the next stage: inputs are validated at the boundary, state mutations are ordered deterministically, and latency/resource costs are bounded so downstream consumers never observe a torn or partially initialized state.

Production invariants and failure modes

Done when the worked check holds: A user updates a profile and immediately sees stale data from a cache. When debugging or capacity-planning this flow in production, instrument each stage boundary separately (measuring both p50 median and p99.9 tail latency), verify what happens when an intermediate stage times out or drops packets, and ensure retry or fallback paths preserve end-to-end idempotency.

Not started

Sign in to save your learning progress.

Sign in to save