A cache stampede occurs when a highly requested cached item expires. Multiple concurrent client requests, all experiencing a cache miss, simultaneously query the backend origin to regenerate the value. This sudden spike in traffic can saturate database connections and CPU, potentially causing a cascading failure of the entire retrieval pipeline. The phenomenon is also known as a dog-piling effect or a thundering herd problem at the cache layer.
Glossary
Cache Stampede

What is Cache Stampede?
A cache stampede is a cascading failure mode triggered when a popular cache entry expires, causing a flood of concurrent requests to simultaneously bypass the cache and overwhelm the backend database.
Mitigation strategies focus on preventing concurrent regeneration. External recomputation uses a separate process to refresh the cache before expiration. Probabilistic early expiration allows a random subset of requests to fetch a new value slightly before the TTL lapses. The most robust solution is request coalescing via a mutex lock, where only the first request computes the value while all other concurrent requests wait for the lock to release and then read the newly populated cache entry.
Cache Stampede Mitigation Strategies
A cache stampede occurs when a popular cache entry expires, causing a flood of concurrent requests to simultaneously hit the backend database. These strategies prevent cascading failure by coordinating cache repopulation.
Probabilistic Early Expiration
Instead of a fixed TTL, each request computes a random probability of refreshing the cache as the expiry time approaches. This spreads out the refresh load over a time window.
- Mechanism: At read time, if
current_time > TTL - (TTL * beta * random(0,1)), trigger a background recomputation. - Key Parameter:
betacontrols the width of the recomputation window. - Advantage: No external coordination service required; implemented entirely in the cache client.
External Locking (Mutex)
The first request that detects a cache miss acquires a distributed lock before querying the backend. All other concurrent requests wait on the lock and then read the freshly populated value.
- Implementation: Typically uses Redis (
SETNX), etcd, or ZooKeeper. - Critical Detail: Lock must have a TTL to prevent deadlock if the populating process crashes.
- Trade-off: Adds latency for waiting requests but completely eliminates duplicate backend work.
Stale-While-Revalidate
Serve the expired (stale) cache entry immediately to all requestors while asynchronously triggering a single background refresh. Users never experience the cache miss latency.
- HTTP Context: Standardized via the
Cache-Control: stale-while-revalidate=30directive. - Application Context: Cache libraries return the expired object and spawn a single thread to update it.
- Key Benefit: Eliminates latency spikes for end-users during cache expiry events.
Cache Warming Pipelines
Proactively pre-load the cache with anticipated hot keys before they are requested, often triggered by deployment or known traffic patterns.
- Process: A script or CI/CD step iterates through a manifest of critical keys and populates the cache immediately after a flush or deploy.
- Use Case: Essential for Time-To-First-Token (TTFT) optimization in RAG systems where embedding caches must be hot.
- Risk: Warming incorrect keys wastes memory and can evict genuinely useful data.
Dogpile Prevention via Request Coalescing
Identical concurrent requests for the same key are collapsed into a single backend call. The result is then fanned out to all waiting callers.
- Implementation: A request map tracks in-flight fetches. If a fetch for key
Kis already in progress, subsequent requests subscribe to the same future/promise. - Contrast with Locking: No distributed lock infrastructure needed; works within a single service instance.
- Library Support: Built into many HTTP client libraries and frameworks like Django's cache framework.
Hard Expiry with Soft TTL
Maintain two expiry timestamps: a soft TTL for triggering background refresh and a hard TTL for actual eviction. The soft TTL is set shorter to create a refresh buffer.
- Example: Soft TTL = 50s, Hard TTL = 60s. At 50s, a single thread refreshes the value while others continue reading the old value until 60s.
- Failure Mode: If the background refresh fails, the hard TTL eventually evicts the key, causing a miss.
- Mitigation: Combine with stale-while-revalidate to serve the hard-expired value as a last resort.
Frequently Asked Questions
A cache stampede is a cascading failure mode triggered when a highly popular cached item expires, causing a flood of concurrent requests to simultaneously overwhelm the backend database. Explore the mechanics, causes, and mitigation strategies for this critical distributed systems hazard.
A cache stampede is a cascading failure mode in distributed systems where a popular cache entry expires, causing a flood of concurrent requests to simultaneously hit the backend database or origin service. This phenomenon, also known as a dog-piling or thundering herd problem at the cache layer, occurs when a high-traffic data object—such as a viral social media post or a product inventory count—reaches its Time-To-Live (TTL).
The Failure Cascade
- Expiration: A hot key's TTL expires, and the cache evicts the entry.
- Concurrent Miss: Hundreds or thousands of concurrent user requests arrive and all register a cache miss.
- Origin Stampede: Every single request thread independently attempts to regenerate the value by querying the database.
- Overload: The database, unable to handle the sudden spike of identical, expensive queries, saturates its CPU or connection pool, causing timeouts.
- Propagation: The database failure cascades back to the application servers, resulting in a complete system outage.
This is distinct from a simple cache miss because the concurrency of the regeneration requests is the destructive force, not just the absence of data.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Understanding the cache stampede requires familiarity with the concurrency patterns, caching strategies, and failure modes that surround it. These related concepts form the toolkit for building resilient, low-latency retrieval systems.
Thundering Herd Problem
The broader concurrency failure mode of which a cache stampede is a specific instance. A thundering herd occurs when a large number of processes or threads, waiting for a single resource, are woken simultaneously and overwhelm the system. In the context of a cache stampede, the 'herd' is the flood of requests for the expired key. Mitigation involves request coalescing or jitter to desynchronize competing operations.
Probabilistic Early Expiration
A proactive cache stampede prevention strategy where each read of a cached item has a small, calculated probability of triggering an early, asynchronous refresh before the key's official TTL expires. The probability increases as the expiry time approaches. This ensures that only one or a few requests perform the expensive recomputation, rather than a flood at the hard deadline. This technique is sometimes called XFetch.
Request Coalescing
A reactive mitigation technique where a barrier or lock is placed in front of the cache miss path. When the first request for an expired key arrives, it acquires a lock and begins recomputing the value. All subsequent concurrent requests for the same key check for the lock and, finding it, wait on the result of the first computation rather than starting their own. This collapses N identical backend queries into a single one.
Jitter
A simple but critical technique for desynchronizing events. In caching, jitter is a small, random delay added to a key's Time-To-Live (TTL). Instead of setting a TTL to exactly 60 seconds, a system might set it to a random value between 55 and 65 seconds. This prevents multiple keys that were cached simultaneously from expiring at the exact same moment, naturally distributing the refresh load over a window of time.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us