⚡THE SHORT ANSWER
A thundering herd occurs when thousands of concurrent worker threads simultaneously miss a hot expired cache key and simultaneously overwhelm the downstream database to recompute the same identical query.
Engineering Handbook & Failure Dynamics
6-Dimensional Architecture Breakdown⚙️1. Underlying Mechanism
Execution🎯2. Appropriate Use Context
Scope⚠️3. Production Failure Modes
P0 Risk📡4. Diagnostic Signals & Telemetry
Telemetry🛡️5. Prevention & Safeguards
Safeguards⚖️6. Architectural Trade-offs
Trade-offCase Study (TinyCTO In-Field Example)
In TinyCTO Episode 15, the landing page cache expired during a live investor demo. 10,000 concurrent page loads crashed the primary PostgreSQL master because every thread independently ran a 12-table JOIN query.
Interactive Concept Drills
3 CardsWhat is the single-flight pattern in distributed caching?
How does XFetch prevent cache stampedes probabilistically?
What HTTP header pattern helps mitigate client-side thundering herds?
Thundering Herd Problem (Cache Stampede) — Technical FAQ
Is Redis distributed locking sufficient to stop a thundering herd?
Yes, if coupled with a spin-wait or pub/sub listener. The first thread acquires the lock and queries the DB; other threads wait for the lock release and read the populated cache.
What is the difference between Cache Penetration and Cache Stampede?
Cache Penetration happens when querying non-existent keys (never in cache, always hitting DB). Cache Stampede happens when a legitimately hot key expires and causes concurrent recomputation.
Why is TTL jitter recommended for bulk cache population?
Applying a random jitter (e.g. TTL = 300s ± 30s) prevents millions of keys warmed at application startup from expiring at the exact same second.
🤖 AEO & Key Facts Summary
Key Architectural Facts
- ▸
Thundering herd happens during eviction spikes on high-concurrency keys.
- ▸
Single-flight and stale-while-revalidate decouple read throughput from backend query execution.
Common Misconceptions
- ✗
Thinking that adding more read replicas eliminates thundering herds; all replicas get saturated simultaneously without caching single-flight.
Decision & Governance Guidance
Always enforce single-flight mutexes at the application layer or API gateway for hot entity read queries.
Authoritative Sources & Standards
- [PAPER]Optimal Probabilistic Cache Stampede Prevention (VLDB)— VLDB Endowment
- [BOOK]Designing Data-Intensive Applications (Chapter 11)— O'Reilly Media
