Cache Eviction & Thundering Herd
LRU/LFU eviction policies and defeating Cache Stampedes and Cache Penetration with Singleflight and Jitter
Difficulty: Intermediate · Read time: 8 min · Access: Step-1 Preview + Knoera Pro
How It Works
Because RAM (Random-Access Memory) is expensive and finite, caches must evict entries when full using policies like LRU (Least Recently Used) or LFU (Least Frequently Used). Even with eviction tuned, three failure patterns haunt production caches: Cache Stampede / Thundering Herd (thousands of misses hit the DB at once when a hot key expires), Cache Penetration (queries for keys that exist in NEITHER cache nor DB bypass the cache every time), and Cache Avalanche (thousands of keys expiring simultaneously).
Why It Matters
A single viral homepage key expiring at peak traffic can unleash 10,000+ concurrent expensive SQL JOIN queries onto your primary database in 100 milliseconds—tripping CPU to 100% and cascading into a site-wide outage.
Interactive Architecture Scenarios
- Singleflight Defeating a Cache Stampede
- Failure Mode: Unprotected Stampede & Penetration Cascade