1async function getProduct(id) {
2 const key = 'product:' + id;
3 const cached = await redis.get(key);
4 if (cached) return JSON.parse(cached);
5
6 const product = await db.products.findById(id);
7 await redis.set(key, JSON.stringify(product), 'EX', 300);
8 return product;
9}
no lines flagged
#114PracticeHard20 min · 200 XP
Cache Expiry Triggers a Thundering Herd
Every five minutes, almost exactly on the minute, database CPU spikes to 100% for a few seconds and latency across the whole site degrades.
Flagged linesNo lines flagged yet
Flag a line or write a note to submit.