CodePark/ questions / Invalidation, stampedes & consistency
START PRACTICINGPRACTICE
Backend question · Redis & caching › Invalidation, stampedes & consistency

A nightly job warms 200,000 cache keys, all with EX 3600. Why add a random offset to each TTL?

So the keys do not all expire at the same moment and send a burst of misses to the database

So the keys do not all expire at the same moment. Keys written together with the same TTL expire together. An hour later, that causes one big wave of misses to the database. Jitter spreads the reloads out, for example 3600 seconds plus a random 0 to 300 seconds.

"Redis rejects identical TTLs on many keys" is wrong: Redis has no problem with identical TTLs.