A cache hit rate can look healthy right up to the moment a single expired key turns into 50,000 database reads per second. That is what makes cache stampede causes dangerous: they are not ordinary cache misses spread across a workload. They are a coordinated loss of protection around an expensive origin operation, often amplified by retries, autoscaling lag, and request queues that were sized for the cached path.
The familiar description is simple: many requests miss the same cache key and recompute it concurrently. Production incidents are usually less simple. A popular key may expire at the same moment across regions. A refresh worker may die after deleting a value. A downstream timeout may make a valid-but-slow regeneration appear unavailable. The result is not merely elevated database CPU. It is a positive feedback loop in which origin latency produces more concurrent work, which produces more latency.
The mechanics behind cache stampede causes
A cache protects an origin by collapsing a large request population into a smaller population of cache fills. For a hot key, the normal relationship is stark: 20,000 reads per second can become one origin read every few minutes. At expiration, that relationship reverses unless the system explicitly coordinates regeneration.
Suppose a key has arrival rate λ and a regeneration time R. After expiry, roughly λR requests can arrive before the first recomputation finishes. At 10,000 requests per second and a 400 ms origin path, that is 4,000 contenders for the same value. If each contender independently executes a query, the database does not receive one 400 ms query. It receives thousands of concurrent queries competing for connections, locks, buffer pool pages, CPU, and network bandwidth.
The important distinction is between a cache miss and a cache stampede. A broad set of cold keys may create normal miss traffic that scales with the working set. A stampede concentrates demand on one or a few keys whose recomputation cost is high and whose request popularity is extreme. Hot catalog pages, tenant configuration objects, authorization-policy bundles, feature-flag snapshots, leaderboard aggregates, and LLM prompt-prefix artifacts are common examples.
Synchronized expiration creates artificial coordination
The most common trigger is deterministic TTL behavior. If an application writes a large batch of related keys with the same 10-minute TTL, it has quietly scheduled a future origin surge at minute ten. This often happens during deploy-time warming, cache flushes, bulk imports, or a recovery job that repopulates Redis from a shared source.
Even when keys are not written in one batch, aligned TTLs can emerge from implementation details. A service may cache all tenant settings after a configuration rollout. A CDN, regional Redis tier, and in-process cache may each use the same expiration policy. Their misses then become correlated across layers instead of being absorbed progressively.
TTL jitter reduces this correlation, but it is not a complete answer. Adding a random 0 to 60 seconds to a 15-minute TTL helps distribute routine refresh work. It does not protect a key that receives thousands of reads per second during its individual expiration window. Nor does it address a coordinated invalidation event.
Explicit invalidation is often more explosive than expiry
Teams usually investigate expiration first because it is visible in cache metrics. Invalidation deserves equal suspicion. A broad wildcard delete, namespace version bump, Redis failover with lost volatile data, or deployment that changes serialization format can invalidate a large fraction of the working set instantly.
This is particularly hazardous when the fallback path performs fan-out. One missing account profile may trigger reads to an identity service, an entitlements service, and a billing store. If each service has independent retries and its own cache, a single top-level invalidation can multiply across the dependency graph. The cache stampede is then distributed: no single cache metric looks catastrophic, but every origin tier sees a burst.
Versioned keys are useful for correctness, especially when stale data is unacceptable. They also create a cold-start event whenever the version changes. Treat a namespace bump as a capacity event, not a metadata operation. Rate-limit rewarming, prioritize critical keys, and verify that origin connection pools can tolerate the planned miss volume.
Hot-key skew turns ordinary policies into failures
Most workloads follow a skewed distribution. A small fraction of keys accounts for a disproportionate share of traffic, and one viral object can dominate a region within minutes. A fixed TTL policy that is safe for median keys can be unsafe for the top 0.01%.
Hot-key failures become sharper in multi-tier architectures. An L1 process cache may expire independently on every application instance. If 500 pods use the same 30-second local TTL, one remote Redis key can receive 500 refresh attempts. If Redis expires too, all 500 pods can fall through to the database. Autoscaling worsens the pattern because newly started pods begin with empty L1 caches and commonly synchronize on startup traffic.
The same effect appears in AI systems. A cache miss for a popular model configuration, retrieval result, or shared prompt prefix may trigger expensive vector retrieval or GPU-bound prefill. The resource under pressure is not necessarily a relational database. It may be a rate-limited external API, a GPU inference pool, or a control-plane service with strict concurrency limits.
Why retries and queues make the blast radius larger
A stampede becomes an outage when overload control is absent or layered incorrectly. Once origin latency rises, clients hold connections longer. Thread pools fill, async task queues accumulate, and upstream deadlines expire. Retry policies then create more work precisely when the system has less capacity to perform it.
A retry can be rational for an isolated transport error. It is destructive for a predictable overload response on a shared hot key. Retries should be budgeted across the call chain, use exponential backoff with jitter, and stop before the caller’s useful deadline. More importantly, the cache-fill path needs its own concurrency discipline. Do not let every request that timed out waiting for a fill become an independent fill attempt.
Watch for hidden duplication in asynchronous designs. A request handler may enqueue a refresh, time out, and then enqueue another refresh on retry. A consumer group may redeliver a slow job while the original worker is still executing. Idempotency prevents corrupt writes, but it does not prevent costly duplicate reads. For expensive regeneration, deduplication must cover work admission, not only result storage.
Design the fill path as a coordination protocol
The primary defense is request coalescing, also called single-flight. The first caller that observes a miss becomes the leader for that key. Other callers join the in-flight computation and receive its result, an explicit overload response, or a bounded stale value. The critical implementation detail is scope: an in-process promise map coalesces only within one process. A fleet-wide hot key requires distributed coordination or a cache tier that provides it.
A distributed lock can work, but simplistic locks introduce their own failure modes. The lock TTL must outlive legitimate regeneration without lingering after a crashed worker. Lock ownership must be fenced if a stalled worker can resume after its lease expires. Waiting callers need a short, bounded strategy; blocking thousands of request threads behind a lock merely moves the stampede into the application tier.
For many read paths, stale-while-revalidate is a better trade. Store a soft expiration and a hard expiration. Between them, serve the last known value while one actor refreshes asynchronously. After the hard expiration, either coalesce a synchronous refill or fail according to the data contract. This keeps user traffic off the origin during refresh, but it is only valid when bounded staleness is acceptable. Authorization revocations, inventory reservations, and fraud decisions often need stricter semantics.
Probabilistic early refresh is another useful tool for highly popular keys. Rather than waiting for a hard TTL boundary, allow a small and increasing fraction of reads to refresh the object as it approaches expiry. The objective is to spread refreshes over time, not to refresh on every read. It works best when refresh cost is moderate and values can safely overlap; it is a poor fit for writes with externally visible side effects.
When regeneration is truly expensive, isolate it behind a queue or a dedicated worker pool with per-key admission control. The serving tier should have a defined behavior while the result is unavailable: serve stale, return a partial response, shed low-priority traffic, or provide a retry-after signal. Letting customer-facing request handlers directly compete for scarce database or GPU capacity is usually the wrong architecture.
Measure miss storms before they reach the database
Cache hit rate is too blunt to detect this class of failure. A 98% global hit rate can conceal total failure for the one key that matters. Instrument key-level or key-class metrics for request rate, miss rate, regeneration duration, concurrent fill count, lock contention, stale-served count, and origin calls per cache fill.
The most valuable derived signal is amplification: origin executions divided by distinct cache-fill events for a key class. Under effective coalescing, it should stay close to one. A sudden rise tells you that coordination has failed even if the cache fleet is otherwise healthy. Pair that signal with database pool wait time, queue depth, timeout rate, and retry volume to see the feedback loop forming.
Test this deliberately. In a load environment, expire a top key while maintaining realistic traffic, then inject a 5x slower origin. Repeat while one refresh worker is killed and while a regional cache node is unavailable. A system that only survives the ideal refill path has not solved the stampede problem.
The operational goal is not to eliminate cache misses. It is to ensure that a miss remains a bounded, coordinated event rather than permission for every caller to attack the same dependency. Treat hot-key regeneration as shared work with explicit ownership, deadlines, and fallback behavior, and the cache will continue to act as a load-shedding boundary when production traffic is least forgiving.


Leave a Reply