Jitter cache TTLs so keys do not expire together
A cache warmed at deploy writes every key in the same second with the same TTL, so an hour later they all expire in the same second and the database gets the whole working set at once. Spread the expiry at write time.
const ttl = 3600 + Math.floor(Math.random() * 600);
await redis.set(key, value, { EX: ttl });Ten minutes of spread on an hour turns the spike into a trickle. Coalescing in-flight misses does not save you here, every key is a different key, so there is nothing to coalesce.
cachingperformance