Skip to content
Preptima
hardDesignScenarioMidSeniorStaff

A popular key expires and forty thousand requests reach the database in the same second. What do you change?

A cache stampede happens when one hot key expires and every concurrent miss rebuilds the same value. Let one request rebuild while the rest wait or serve stale, then prevent repeats with stale-while-revalidate, jittered TTLs and refresh-before-expiry. Use this caching answer to show the decision, trade-off, and evidence rather than a memorised definition.

5 min readUpdated 2026-08-15

Answer

Short answer

A cache stampede is duplicate rebuild work, not ordinary traffic. Use single-flight locking so one request rebuilds the hot value while others wait, or serve the stale value while one request refreshes it in the background. Then add TTL jitter and early refresh so hot keys do not expire together or wait until the first miss to be rebuilt.

Was this answer helpful?

Likely follow-ups

  • The single rebuilding request fails with a database timeout. What do the waiters see, and who retries?
  • How would you refresh a value before it expires without knowing in advance which keys are hot?
  • Your cache is a cluster and the hot key lives on one node whose CPU is now saturated. What changes?
  • When is it correct to let the stampede happen and protect the database with a queue instead?

Related questions

Further reading

Related Topics