Thundering Herd & Cache Stampede
When a popular cache entry expires, every concurrent request may miss at once and hammer the database — the thundering herd problem. At scale this can take down your database in seconds. A related pattern, cache stampede, happens when many requests simultaneously try to regenerate the same expired entry. Solutions exist at every level. Locking (or mutex): only one request regenerates the value; others wait or get the stale value. Request coalescing (singleflight): duplicate in-flight requests for the same key share one backend call. Jittered TTLs: instead of every key expiring at exactly 300 seconds, expire between 270–330 seconds so expirations spread over time. Probabilistic early expiration: each request has a small chance of refreshing the cache before TTL expires, spreading regeneration load gradually.