Inferensys

Glossary

Cache Stampede

A cascading failure scenario where a popular cache entry expires, causing a flood of concurrent requests to simultaneously hit the origin model or database, overwhelming backend resources.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
CASCADING CACHE FAILURE

What is Cache Stampede?

A cache stampede is a pathological failure mode in high-concurrency systems where the expiration of a popular cache entry triggers a flood of simultaneous requests to the origin backend, overwhelming it.

A cache stampede occurs when a heavily requested cached item expires, and multiple concurrent client requests simultaneously discover the miss. Instead of a single request regenerating the value, a thundering herd of requests storms the origin database or LLM inference endpoint, causing massive latency spikes or a complete backend outage. This is especially dangerous in sovereign inference caching where local compute resources are finite and cannot auto-scale to absorb the surge.

Mitigation strategies include probabilistic early expiration, where a request randomly refreshes the entry before its strict TTL elapses, or external recompute locking that serializes regeneration. For semantic caches, a stampede can be triggered by a sudden shift in query patterns that bypasses the Locality-Sensitive Hashing (LSH) buckets, requiring the circuit breaker pattern to protect the origin model from collapse.

CACHE STAMPEDE DEFENSE

Key Mitigation Strategies

A cache stampede occurs when a popular cache entry expires, causing a flood of concurrent requests to simultaneously hit the origin model or database. The following strategies prevent this cascading failure by coordinating cache repopulation and protecting backend resources.

01

Probabilistic Early Expiration

Instead of using a fixed Time-To-Live (TTL) , the cache layer randomly expires entries within a window before the nominal deadline. When a request encounters an entry nearing its logical expiry, it proactively recomputes the value while still serving the stale data to other requestors.

  • Prevents synchronized mass expiry of popular keys
  • Distributes recomputation load across a time window
  • Works best when combined with exponential backoff on misses
99.9%
Stampede Reduction
< 5ms
Recomputation Jitter
03

Circuit Breaker with Stale Fallback

A circuit breaker monitors the health of the origin backend. When failure rates or latency exceed a threshold, the breaker trips and the cache layer serves stale data beyond its nominal TTL rather than forwarding requests to a failing origin.

  • Implements graceful degradation under load
  • Requires application tolerance for eventually consistent data
  • Automatically resets when the origin recovers
04

Request Coalescing

The cache proxy or middleware collapses multiple identical in-flight requests into a single origin query. When the response returns, it is fanned out to all waiting clients. This is a fundamental pattern in Nginx, Varnish, and Envoy.

  • Reduces origin load by orders of magnitude during spikes
  • Transparent to client applications
  • Often combined with token bucket rate limiting for defense in depth
05

Dog-Pile Prevention via Background Refresh

A background worker monitors hot keys and proactively refreshes them before expiry. When a key's remaining TTL drops below a threshold, the worker asynchronously recomputes the value and updates the cache, ensuring the entry never actually expires under normal conditions.

  • Eliminates cache misses for predictable, high-traffic keys
  • Requires knowledge of access patterns or manual key registration
  • Pairs well with cache prefetch strategies
06

Token Bucket Rate Limiting

A token bucket algorithm placed in front of the origin enforces a strict maximum request rate. Tokens are generated at a fixed rate and consumed by each forwarded request. When the bucket is empty, excess requests are immediately rejected with a 429 Too Many Requests status.

  • Protects the origin from any surge, stampede or otherwise
  • Provides backpressure that propagates to clients
  • Can be implemented at the API gateway or service mesh layer
CACHE STAMPEDE

Frequently Asked Questions

A cache stampede is a cascading failure scenario where a popular cache entry expires, causing a flood of concurrent requests to simultaneously hit the origin model or database, overwhelming backend resources. The following questions address the mechanics, causes, and mitigation strategies for this critical infrastructure pattern.

A cache stampede is a cascading failure event where a highly popular cached item expires, and multiple concurrent requests for that item simultaneously miss the cache and hit the backend origin. This occurs when a Time-To-Live (TTL) expires on a hot key—such as a frequently queried LLM prompt or a trending product page—and dozens or hundreds of parallel threads all detect the miss at the same instant. Each thread independently initiates a regeneration request to the database or model inference endpoint. The sudden spike in load can saturate connection pools, exhaust thread resources, and trigger circuit breakers, effectively causing a self-inflicted denial-of-service condition. The phenomenon is particularly dangerous in sovereign inference caching environments where the origin model runs on finite, privately owned GPU clusters with hard throughput limits.

Prasad Kumkar

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.