Sphere
Log in Join
☆ 15

Redis keys expire at the same time and the database spikes

About 4000 cache keys all written during a deploy with a one-hour TTL. At the hour mark the DB gets hammered. Adding jitter helped but did not fully fix it.

⚑ Report

3 replies

☆ 0
M Mike ·2026-10-31#1

Jitter spreads the expirations but a cold cache still means 4000 misses. Add a lock per hot key so only one request rebuilds it.

⚑ Report
☆ 0
A Anna ·2026-10-31#2

How do you lock without making other requests wait too long?

⚑ Report
☆ 0
N Nina ·2026-10-31#3

SET key:lock value NX EX 10. If you lose, sleep 50 ms and read the cache again. Only the winner queries the DB.

⚑ Report
Log in to reply.