Lesson 25 / 25

Revision and Interview Questions

Recall caching and CDN concepts quickly for exams and system design interviews.

Cheat sheet

Why cache: lower latency, lower origin load, absorb spikes, lower cost; cache read-heavy, expensive, staleness-tolerant data. Layers: browser, CDN, reverse proxy, in-process, distributed (Redis/Memcached), database buffers. Metrics: hit ratio, effective latency = h × hit + (1 − h) × miss; origin load ∝ miss ratio; working set and skew. Patterns: cache-aside (most common), read-through, write-through, write-behind (risk of loss), write-around; TTL with jitter, refresh-ahead, negative caching. Invalidation: TTL vs explicit; delete rather than set; versioned keys; tags; events and CDC; stale-set races, leases, double delete; read the source of truth for decisions. Failures: stampede (coalescing, stale-while-revalidate, XFetch), avalanche (jitter, replication), penetration (negative caching, Bloom filters), hot and big keys (L1, replication, small values). Eviction: LRU, LFU, TinyLFU, TTL; Redis maxmemory-policy. Distributed: Memcached vs Redis/Valkey, consistent hashing, Redis Cluster 16,384 slots, hash tags. HTTP: Cache-Control max-age, s-maxage, public/private, no-cache vs no-store, immutable; ETag/Last-Modified and 304; Vary; stale-while-revalidate, stale-if-error; fingerprinted assets. CDN: PoPs, anycast, shield, cache keys, purge by tag, micro-caching, edge compute, WAF/DDoS, origin lock-down. Security: never share private responses; cache deception and poisoning.

Common interview questions

Answer each with a mechanism and a trade-off.

1. Explain cache-aside and how you invalidate on writes.
2. Write-through vs write-behind: trade-offs?
3. What is a cache stampede and how do you prevent it?
4. How would you avoid serving stale prices at checkout?
5. LRU vs LFU: when would each work better?
6. Memcached vs Redis: when would you choose each?
7. no-cache vs no-store vs private: what do they mean?
8. How do ETags and 304 responses save bandwidth?
9. How does a CDN decide whether two requests share a cached object?
10. Design caching for a product catalogue serving 30,000 requests per second.

Always state staleness and invalidation

Saying "add Redis" is not a design. A strong answer says what is cached, for how long, how it is invalidated, what happens on a miss storm, and what must never be cached.

Quick check: Which header value tells caches they may store a response but must revalidate it before every use?

  • no-store
  • immutable
  • public, max-age=31536000
  • no-cache
Answer

no-cache — no-cache permits storage but requires revalidation; no-store forbids storage.