In short. Cache repeated reads only under an explicit freshness and identity contract. Bound refill work independently of the warm hit rate.
A timer is not a source of truth
A time-to-live limits a cache entry's permitted reuse according to a particular timer policy. It does not prove that the data was current when inserted or that the underlying state has not changed. An application cache also needs to decide when the timer starts and which events invalidate an entry.
RFC 9111 defines HTTP cache freshness, validation and restrictions on reusing responses. That contract is more precise than a general claim that every cached result is reusable until an arbitrary local timer expires. Application-level object caches need their own explicit rules rather than assuming HTTP directives solve every state problem.
Cache keys are equally important. If a result depends on language, source revision, account, permissions or other inputs, omitting a relevant distinction can produce a fast wrong answer. Including identity in a key is useful isolation, but it does not replace an actual authorization check for the requested data.
Read through the validity boundary
A cache-aside read first asks whether a usable entry is present. On a miss, the application reads the source and may publish a reusable representation. The write path must explain whether it invalidates, refreshes or versions that representation. A reader and writer can interleave, so describe those steps as concurrent operations rather than a decorative straight line.
Versions can help prevent an older refill from overwriting a newer entry, but the version comparison must itself be enforced by the chosen mechanism. Simply attaching a version number to text does not make concurrent writes safe. Nor does invalidating a shared cache automatically invalidate copies held by other layers.
Redis is the shared in-memory copy; Postgres remains authoritative for Northwind’s prices. In cache-aside, the application looks in Redis, reads Postgres on a miss, and fills Redis. Write-through makes the write path update the cache as part of its success contract. That adds write-path dependency and still requires a defined response if the database write succeeds while the cache update fails. Write-behind acknowledges a cache write before durable storage catches up. Its crash and replay requirements make it a poor default for an authoritative checkout price.
Eviction answers a different question from expiration: which entry leaves when memory is full? Redis offers approximate least-recently-used (LRU) and least-frequently-used (LFU) policies. LRU suits recent reuse but a scan can displace frequently useful older entries. LFU can preserve repeatedly popular items but may adapt more slowly when the hot set changes. Redis’s eviction documentation explains its sampling and frequency approximation; measure keyspace hits, misses and evictions under the actual access pattern.
A hot key concentrates work on one key even when the total key count looks small. Adding shards spreads different keys; it does not divide requests for one key automatically. A small local copy can reduce network reads when the display contract permits it. That adds another invalidation boundary. A cache stampede is the refill wave when many readers simultaneously discover a missing or expired key. A fast Redis lookup cannot prevent those readers from overloading Postgres afterward.
Calculate the warm path and the refill wave
Hypothetical scenario. Choose a read rate of 1,000 requests/s and a hit fraction of 0.9. Warm hits are 1,000 × 0.9 = 900/s; misses are 1,000 − 900 = 100/s. Under one-source-read-per-miss accounting, the source sees 100 reads/s before considering writes, refreshes or retries.
Choose exactly 2 ms for a hit and 40 ms for the entire miss path. The weighted mean is 0.9 × 2 + 0.1 × 40 = 1.8 + 4 = 5.8 ms. These are chosen path times, not observations. This calculation establishes neither a percentile nor behavior under contention; a small slow fraction can matter greatly to users whose requests consistently miss.
For a refill example, assume a popular entry expires and exactly eighty requests arrive during a 0.4-second refill window. Their average rate over that window is 80 ÷ 0.4 = 200 requests/s. Without coordination, every request may issue a duplicate source read. If one in-flight refill is shared within each of six independent application processes, up to six concurrent refills can still occur. Process-local coordination is not automatically global coordination.
For a separate age example, choose a value already 45 seconds old when inserted into an application cache. If a local timer permits another 60 seconds of reuse without validation, the value can approach 45 + 60 = 105 seconds old before that timer expires, under the stated clock and age assumptions. This is why a local timer duration and source-data age are different quantities.
Do not turn these examples into universal settings. Refill cost, popularity, expiration patterns and permissible age depend on the application. Capacity planning should include misses, refresh work, cold starts and coordination failures rather than budgeting only the 900 warm hits.
Toy math: launch-day price miss. Choose 1,000 simultaneous readers and a 60-second TTL. If they all observe one expired key before any fill completes, the uncoordinated plan issues 1,000 identical Postgres reads. Coalescing across the whole service reduces this wave to one active refresh plus waiting readers; coalescing separately in six processes permits six refreshes. The distinction is coordination scope, not Redis lookup speed.
Size the working set from distinct items touched during the reuse window. Assume 100,000 catalogue items, and that the hot 20% of items account for 80% of reads. The candidate hot set contains 100,000 × 0.20 = 20,000 items. At a chosen 2,000 bytes per cached representation, payload is 20,000 × 2,000 = 40,000,000 bytes, or 40 decimal MB. This is 20% of item count, not 20% of read volume. A hypothetical 50% allowance adds 20 MB for a 60 MB planning subtotal; measure actual keys, object overhead, fragmentation and buffers before setting the process limit.
In the wild: Facebook’s leases make refills a protocol
Nishtala and colleagues’ Scaling Memcache at Facebook describes leases for coordinating fills and dealing with stale-set races. The paper’s value here is the identified concurrency problem and its protocol, not a promise that Northwind should copy Facebook’s scale. A reader that misses needs controlled permission to refill; invalidation can make previously granted work obsolete.
For Northwind, trace a price update against a paused refill. Decide who may publish after the update, and how a delayed worker learns that its earlier result is no longer eligible. Treat this as a state transition that the implementation must enforce. A timer attached to an old result cannot establish that ordering by itself.
Stale data and stale work need different policies
Some pages may tolerate a previously valid description while a refresh occurs. Other operations, such as accepting a reservation against current stock, require a stronger decision. Define permitted staleness by operation and consequence; do not let a performance optimization silently choose business semantics.
Refresh policies can use early refresh, distributed expiration, coalesced work or bounded concurrency. Each has costs. Coordination can fail, a lease can expire before work finishes, or one slow refresher can delay many readers. The application needs a timeout and fallback that respects its correctness requirement.
Negative caching also needs a contract. Reusing “not found” can reduce repeated failed lookups, but an item may be created or permissions may change. Choose identity, lifetime and invalidation for negative results rather than assuming an absence is permanent. Do not use a shared negative result to conceal an authorization boundary.
An edge cache or CDN adds a reuse boundary closer to readers. Decide which representations are shareable, how request variants affect the key and how source changes reach that layer. A private response must not become public merely because it crosses an intermediary. An origin-side invalidation does not establish that every edge copy has changed; evaluate HTTP cache directives and application permissions together.
Separate four ways to control refill work. Coalescing makes concurrent requests share a refill under a defined coordination scope. Stale-while-revalidate lets eligible readers use an older value while refresh happens. TTL jitter spreads the expiration times of different keys. Probabilistic early refresh spreads opportunities to refresh one key before its deadline. These choices address different concentrations of work.
Hypothetical scenario. Let an entry expire at time 100 seconds and let its previous recomputation take Δ = 2 seconds. In Vattani, Chierichetti and Lowenstein's XFetch, Figure 3, refresh when now − Δ × β × ln(U) ≥ expiry, where U is uniform in (0, 1] and β is a positive tuning parameter that defaults to 1. Store the measured recomputation duration with the value. The logarithm is natural; all time quantities must use the same unit.
Choose β = 1 and U = exp(−1), so ln(U) = −1. At now = 97, the test gives 97 − 2 × 1 × (−1) = 99, below expiry 100: this request does not trigger early refresh. At now = 99, the same chosen draw gives 101, reaching the threshold. These are selected draws for arithmetic, not observed refresh frequencies. Larger random forward gaps can trigger earlier.
This method needs a usable expiry time and a recorded recomputation duration. It does not grant permission to serve stale content, enforce one global refresher or protect the source from every cold-cache burst. Combine it with a bounded refill policy where required. In an authorization-sensitive response, eligibility must still be checked before reuse.
Consider a different race: reader R fetches source revision 7; writer W publishes revision 8 and invalidates the cache; R then tries to fill revision 7. A version-aware publish boundary must reject that obsolete refill or make it ineligible to readers. A lock that expires while R pauses does not prove R can no longer publish. Trace the enforcing write boundary rather than assuming that owning a lease once makes later work current.
The semantic-answer-cache case applies those questions to generated answers. The document-assistant case adds source revisions and permission changes. Choose a refresh policy only after deciding which object is reused, which age is acceptable and how much source work can be admitted during recovery.
An answer cache needs question identity, evidence revision and permission scope in its lookup contract. A changed policy or revoked access invalidates the derived answer even if its timer is fresh. A cache key limits accidental collisions; authorization still decides whether the caller may receive the underlying evidence.
Cache promises that need evidence
“More RAM guarantees more hits.” Allocation does not establish the popularity distribution or that useful entries are present.
“A high average hit rate protects every tenant.” Aggregation can hide a hot key, a cold tenant or an expensive class of misses.
“An invalidation message proves nobody can read the old value.” Concurrent fills and additional cache layers require their own ordering and visibility rules.
“A cache outage should simply bypass to the source.” That fallback can exceed source capacity. Admission and correctness requirements still apply.
Reuse only what the operation allows
Use caching where repeated work is material and a scoped validity policy can be implemented. Measure saved resource work, not only the existence of hits. Separate response-cache behavior from authoritative state and distinguish user-visible freshness from a particular storage timer.
Do not cache a result whose relevant identity or authorization dependencies are unknown. Avoid adding a cache merely because a reference architecture contains one. The resulting invalidation and recovery complexity must be justified by a concrete workload.
The queueing lesson next moves some work out of the request path. The distinction carries forward: acknowledging that work has been scheduled, like returning a cached view, is not proof that every underlying state transition is complete.
Limits of this estimate
The examples count declared payload and source operations; they omit measured queueing, Redis object overhead and failure timing. Early refresh does not establish one global winner, a lease needs enforced publication rules, and serving stale data remains an operation-specific business decision. Validate checkout against authoritative prices and bound the cold-cache path before relying on warm-path capacity.
Check yourself: follow the cached value
An entry's local timer is fresh, but the result belongs to a different account. May it be reused?
No. Timer state does not override identity or authorization. The request must satisfy the correct scope and access contract.
Six processes each coalesce local requests. Does that prove exactly one source refill?
No. Each process can still start its own work. Cross-process coordination, if needed, introduces a separate contract and failure behavior.
A source update invalidates an entry before an old read publishes its result. What must the design prevent?
It must prevent the older refill from becoming a valid newer representation under the chosen policy. Trace revisions and atomic ordering; repeating invalidation blindly does not establish that invariant.
Northwind decision log
Coalesce refreshes for a hot key before querying Postgres.
Allow stale prices only under an explicit display contract.
Validate the final checkout price against the source.
Go deeper: cache behavior before cache settings
- Video lecture: Scaling Memcache at Facebook — Rajesh Nishtala and colleagues, USENIX NSDI 2013. Watch first to connect refill coordination to real service boundaries.
- Book chapter: Redis in Action, chapter 2: Anatomy of a Redis web application — Josiah Carlson. Connect cache patterns to application read paths.
- Book chapter: Redis in Action, chapter 3: Commands in Redis — Josiah Carlson. Understand the operations underlying the cache protocol.
- Primary paper: Optimal Probabilistic Cache Stampede Prevention — Andrea Vattani, Flavio Chierichetti and Keegan Lowenstein. Derives the early-refresh rule and its assumptions.