12. Interview Framing
The questions that actually get asked, and the sharpest honest answer to each
Q: How would you handle a cache stampede on your most popular endpoint?
Protect the hot key specifically: locking or request coalescing so only one request refetches while the rest wait, stale-while-revalidate so nobody has to wait at all, and jittered TTL so keys don't all expire in the same instant. Combine at least two of these - don't rely on just one.
Q: What's the actual difference between Redis and Memcached?
Memcached is simpler - pure key-value, multi-threaded, no persistence. Redis does much more: rich data structures, pub/sub, optional persistence. A fast disposable cache favors Memcached; needing atomic counters, sorted sets, or the cache doubling as pub/sub infrastructure for invalidation favors Redis.
Q: Walk me through what happens if your cache goes down entirely.
Every request that would've hit cache now hits the database directly - the same shape as a stampede, except permanent instead of momentary. Never treat a cache as load-bearing for correctness: have a circuit breaker or graceful-degradation path, and make sure the database can survive reduced service rather than fall over completely.
Q: How do you keep a cache consistent with the source of truth?
TTL, write-invalidate, or event-driven - chosen by how much staleness is tolerable. The detail people miss: even write-invalidate has a race (section 9) - a slow reader can overwrite a fast writer's invalidation with stale data. The safer pattern is invalidating the cache before writing the database, or using a versioned write so a stale write can be detected and rejected.
Q: When would caching make things worse, not better?
When data is written far more than it's read - all the invalidation cost, none of the benefit. When data must be immediately, strongly consistent - a live account balance. And when data is highly personalized, one-shot content that's never re-read - a cache that's only ever used once has the full cost and none of the payoff.