Users see stale product prices for several minutes after an update. How do you fix the caching design?
Short answer
Shorten or separate the TTL for fast-changing fields, invalidate on change using events or CDC rather than relying only on TTLs, delete rather than update cache entries on writes, purge CDN entries for affected pages, and never use cached prices for the final charge, which must come from a validated quote.
Detailed answer
- Split cache entries: static product content (long TTL) vs price/stock (short TTL, seconds).
- Event-driven invalidation:
PriceChangedevents (from outbox or CDC) trigger cache deletes and CDN purges by surrogate keys/tags. - Write path: update DB, then delete cache key (avoid set-race); consider delayed double delete for replica lag.
- Checkout: recompute from source of truth and show any difference before charging.
- Monitor: staleness metric (time between update and cache refresh).
What the interviewer expects
Understanding of invalidation strategies and separating display from transactional correctness.
Common mistakes to avoid
Only shortening TTLs globally (destroys hit rate); caching prices used for payment.