Pick the fix
A dashboard query takes 2 s and its cache key is read 500 times a second. Slightly stale data is fine. Best protection?
Hint 1 of 1
Is stale data acceptable here?
Choose an answer, then open Show answer below to check it.
Run on Redis 7
Text version
| Slot | Cache | Requests | DB reads |
|---|---|---|---|
| 0–100 ms | ✕ Expired | 10 | 10 |
| 100–200 ms | ✕ Expired | 10 | 10 |
| 200–300 ms | ✕ Expired | 10 | 10 |
| 300–400 ms | ✓ Fresh | 10 | 0 |
| 400–500 ms | ✓ Fresh | 5 | 0 |
| 500–600 ms | ✓ Fresh | 5 | 0 |
| Slot | Cache | Requests | DB reads |
|---|---|---|---|
| 0–100 ms | ↻ Refreshing | 10 | 1 |
| 100–200 ms | ↻ Refreshing | 10 | 0 |
| 200–300 ms | ↻ Refreshing | 10 | 0 |
| 300–400 ms | ✓ Fresh | 10 | 0 |
| 400–500 ms | ✓ Fresh | 5 | 0 |
| 500–600 ms | ✓ Fresh | 5 | 0 |
| Slot | Cache | Requests | DB reads |
|---|---|---|---|
| 0–100 ms | ~ Stale | 10 | 1 |
| 100–200 ms | ~ Stale | 10 | 0 |
| 200–300 ms | ~ Stale | 10 | 0 |
| 300–400 ms | ✓ Fresh | 10 | 0 |
| 400–500 ms | ✓ Fresh | 5 | 0 |
| 500–600 ms | ✓ Fresh | 5 | 0 |
Show answer
Answer: A Stale-while-revalidate: serve the old value while one request refreshes in the background
Correct. No request waits and only one hits the database.
A stampede happens when many requests miss at the same moment and all recompute. Serving the stale value while a single request refreshes keeps latency flat and the database sees one 2-second query.
Why not the others?
- B Increase the TTL to a day. Fewer stampedes, still one big one per day, and stale data for longer.
- C Add read replicas. Spreads the stampede; doesn't stop it.
- D Remove the TTL. Data never refreshes.