What the symptom looks like
Sampling TTLs with redis-cli
redis-cli.
This one-liner scans a sample of keys and prints their remaining TTL in seconds:
BASH
redis-cli --scan --pattern '*' --count 1000 | head -500 | while read key; do
ttl=(redis-cli TTL "key")
echo "ttlkey"
done | sort -n | head -50-1 means the key has no expiry set (it lives forever). A TTL of -2 means the key does not exist (it may have expired between the SCAN and the TTL call). Neither of those is your problem. You are looking for large groups of keys with similar positive TTL values.
If you have many key prefixes (like product:*, session:*, user:*), run the scan per prefix to see which group is clustered:
BASH
redis-cli --scan --pattern 'product:*' --count 1000 | head -200 | while read key; do
echo "(redis-cli TTL "key") $key"
done | sort -nEliminating red herrings
Confirming the stampede pattern
BASH
redis-cli INFO stats | grep keyspace_misseskeyspace_misses during the spike window confirms that the application is requesting keys that no longer exist, triggering database fallback.
Fixing it: add jitter to TTL
base_ttl + random(0, jitter_range).
How much jitter to add depends on how many keys expire together and how much burst your database can handle. A rule of thumb: jitter of 10-20% of the base TTL is usually enough to flatten the spike into a manageable trickle. For a 300-second TTL, that means randomizing between 270 and 330 seconds. For a 3600-second TTL, randomizing between 3240 and 3960 seconds.
This is the simplest fix and handles the majority of stampede cases.
