redis cache stampede when all keys expire at once
Redis 7.2.4, Python 3.11 with redis-py 5.0. Our product page cache keys all expire together (TTL 300s) and when they do about 200 concurrent requests hit Postgres at once. I tried random jitter on the TTL, plus or minus 30s via EXPIRE, helped a bit but still spikes. Is there a standard pattern for this, a lock key, probabilistic early expiration, something built into redis-py? Would rather not pull in another dependency.
3 replies