Interview Q&A · questions with model answers
Caching Interview Questions
Part of the study plan for: Backend Engineer · Full Stack Engineer
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked Explain the main caching patterns: cache-aside, read-through, write-through and write-behind.
Cache-aside: the application reads the cache, and on a miss loads from the database and populates the cache. Read-through: the cache itself loads missing data. Write-through: writes go to the cache…
-
Most asked How does HTTP caching work (Cache-Control, ETag, CDNs)?
Cache-Control tells browsers and CDNs whether and how long to cache (public, max-age=300, private, no-store, s-maxage, stale-while-revalidate); validators (ETag, Last-Modified) let clients…
-
Most asked In cache-aside, why can a value be stale even though you delete the key on every write?
The stale-set race: a reader misses and reads the old row, a writer commits and deletes, then the reader sets the old value — which stays until the TTL. Leases or version-checked sets prevent it;…
-
Most asked How can a CDN leak one user's data to another, and how do you prevent it?
If a personalized response lacks Cache-Control: private, no-store (or the CDN ignores origin headers), the shared cache stores it by URL and serves it to the next visitor. Mark personalized…
-
Most asked In a system design interview, how do you decide what and where to cache?
Identify read-heavy, expensive or latency-sensitive paths and their staleness tolerance; pick the closest safe layer (CDN for public content, Redis for shared computed data, local cache for config);…
-
Most asked How does stale-while-revalidate work, and when is it inappropriate?
After a soft expiry, the cache keeps serving the old value while one background refresh rebuilds it, avoiding stampedes and latency spikes. It's inappropriate for data that must be exactly current,…
-
How do you handle hot keys in a distributed cache?
A hot key receives so much traffic that the single cache node holding it becomes a bottleneck. Mitigate with a local in-process cache in front, replicating the key across shards (key suffixes like…
-
How does Redis scale and stay available?
Redis scales reads with replicas and scales data/writes with Redis Cluster, which shards keys across 16,384 hash slots on multiple primaries; availability comes from replica failover (Sentinel or…
-
What happens if the cache goes down, and how do you design for it?
Without protection, all reads fall through to the database, which may collapse under the load. Design for degraded operation: timeouts and circuit breakers on cache calls, fall back to the DB with…
-
How do frontend applications cache server data?
Libraries like TanStack Query, SWR and Apollo keep a client-side cache keyed by query, serve cached data instantly, refetch in the background when stale, dedupe requests and invalidate after…
-
How does a Bloom filter help in caching systems?
A Bloom filter is a compact probabilistic set that answers 'definitely not present' or 'maybe present'. In front of a cache or DB, it can reject lookups for keys that certainly don't exist,…
-
How do you invalidate thousands of related cache keys (e.g. all pages of a category) efficiently?
Embed a generation number in the keys and increment it; old keys become unreachable instantly and expire by TTL. Avoid KEYS/pattern deletes in production.