‹ All demos
LiveCaching · Databases

Cache stampede

See what happens to the database when many cache keys expire at the same moment — and how two small fixes stop it.

How it works

  1. 1When many keys are cached at the same time with the same expiry, they also expire together. Every request for them misses at once and hits the database.
  2. 2Jitter gives each key a slightly different expiry, so the misses spread out.
  3. 3Single-flight lets only one request refresh a key; the rest wait for that result instead of all querying the database.

Read the post: How to build an API for 100,000 requests a second