Cache Stampede & Thundering Herd Defenses
Prevent database meltdown on cache key expiration: Mutex locking, probabilistic early expiration (XFetch), and background refresh.
01.1. What is a Cache Stampede (Thundering Herd)?
A Cache Stampede (also referred to as the Thundering Herd Problem or Cache Breakdown) is a catastrophic failure scenario that occurs in high-concurrency systems when an intensely accessed, computationally expensive cached key expires or is evicted:
The Anatomy of the Meltdown:
- The Hot Key: A key (e.g.,
homepage:top_dealsorlive_match_score) receives10,000 requests per secondwith a99.99\%cache hit ratio. - Instant Expiration: At 12:00:00 UTC, the key's 1-hour TTL expires, and Redis evicts it.
- The Stampede: At 12:00:01 UTC, all 10,000 concurrent requests encounter a cache miss simultaneously.
- Database Meltdown: All 10,000 application worker threads bypass the cache and fire complex multi-table SQL join queries directly at the primary database at the exact same millisecond.
- Cascading Failure: The database CPU hits
100\%, connection pools are exhausted, queries time out, application threads hang, and the entire platform crashes.
Cache Stampede Meltdown vs Mutex Lock Defense 🛡️
Cache Stampede Meltdown vs Mutex Lock Defense 🛡️
When a hot key expires, thousands of concurrent threads rush the database.
Unlock Topic #105: Cache Stampede & Thundering Herd Defenses
You are viewing a preview. The full in-depth engineering deep dive, interactive simulators, architecture flowcharts, and self-assessment quizzes for this topic are available with Pro or Lifetime Access.
Failure modes, high-throughput bottlenecks, and real FAANG implementation decisions.
Interactive system topology diagrams, live parameter simulators, and downloadable SVG charts.
Staff-level multiple-choice quiz questions with instant feedback and answer explanations.
Firebase Google authentication automatically syncs your completed topics and quiz scores.
How clear and staff-actionable was this system breakdown?