Skip to content

Caching: cache-aside, eviction, stampede

Why a cache's hit rate comes from key skew, how it sets database load, how to keep it fresh, and why a cold restart can take the database down.

25 min9 steps

By the end you can
  • Explain why the hit rate emerges from key popularity skew and cache size
  • Predict database load from request rate and hit rate, and the hit rate a database needs
  • Trace the cache-aside read path on a miss and say who fills the cache
  • Choose between TTL expiry and explicit invalidation for a freshness requirement
  • Explain the stampede after a cache restart and how request coalescing prevents it

A database that cannot keep up

A database answers in about 5 ms and saturates at a few thousand reads/s. A cache answers in under 1 ms, for keys it holds. Hit rate = share of reads the cache answers.

  • Cache hit0.5 ms
  • Database read5 ms

Log scale: each gridline step is 10×.

Move the sliders: compare a 90% and a 99% hit rate.

20,000 rps
90%
5,000 rps

Database load

2,000 rps

Within capacity: 40%

Mean read latency
1 ms
If hit rate drops 1 point
DB load +10%

Assumes a 500 µs cache lookup and a 5 ms database read; a miss pays both.

Answer this step to continue.