Menu

Cache stampedes: when one expiring key takes down the database
📰

Cache stampedes: when one expiring key takes down the database

DEV Community: redis·Ayush Soni·about 9 hours ago
#XLmILX3a
#devtoredis#devto#dev#cache#database
Long article (1309 words) — no AI summary yet.
Reading 0:00
15s threshold

A cache with a 99.8% hit rate can still take your database down.

The usual pattern is cache-aside: check the cache, and on a miss, load from the database and store the result with a TTL. It works beautifully until your most popular key expires. In the next few milliseconds, every request for that key misses, and every one of them runs the same database query. A thousand identical queries arrive at once for data that was in memory a moment ago.

That's a cache stampede , also called dogpiling or a thundering herd. It has an unpleasant property: the busier the key, the bigger the stampede, so it happens exactly when you have the most traffic. It's a well-understood problem with well-understood fixes, and they combine nicely.

Same traffic, one database query instead of a thousand. Explore the interactive diagram

Three ways to start a stampede

A hot key expires. The classic case: one popular product page, one homepage query, one config value.

Many keys expire together.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.