You added Redis in front of an expensive query, and it worked beautifully. The dashboard that took 800 ms now returns in 3 ms. The database CPU dropped from 70% to 10%. Everyone is happy.
Then, one afternoon, the database CPU spikes to 100%, latency goes vertical, and the incident channel lights up. The graphs show a sharp, periodic pattern: calm, spike, calm, spike. Nothing deployed. Traffic didn't change.
What happened is a cache stampede (also called the thundering herd or dogpile problem). A hot key expired, and for the next few hundred milliseconds, every request that wanted it missed the cache at the same moment and ran the expensive query itself.
This post explains exactly how that happens and builds up a set of defenses in Node.js with ioredis , from a ten-line fix to a production-grade helper.
Anatomy of a stampede
Here's the classic cache-aside code:
async function getLeaderboard () { const cached = await redis . get ( ' leaderboard ' ); if ( cached ) return JSON .β¦