CDN Interview & Revision
CDN interviews and design reviews often center on cache invalidation, origin protection, and anycast-vs-DNS routing. This section condenses those into revision notes, a self-test quiz, and a cheat sheet for quick review.
Interview Questions
Use these practice prompts to check whether you can explain CDN definitions, mechanics, and trade-offs clearly.
What is a CDN and why do we need one?
A globally distributed network of edge servers (PoPs) that caches content close to users to reduce latency, offload origin traffic, and commonly provide TLS termination, DDoS absorption, and other edge protections.
Explain the difference between a cache hit and a cache miss.
A cache hit means the requested object is already cached at the edge and is served directly. A cache miss means the edge doesn't have it (or it expired), so it must fetch it from the origin, cache it, then serve it.
How does TTL work, and what happens when it expires?
TTL is the duration a cached object is considered fresh, typically set via Cache-Control max-age. Once it expires, the object is stale; the next request triggers a fresh fetch (or a conditional revalidation) from the origin.
How would you immediately remove a piece of content from all edge caches?
Trigger a cache invalidation (purge) by URL, by tag/surrogate key, or by wildcard pattern — bypassing the TTL entirely.
How does a CDN decide which edge location serves a given user?
Via DNS-based routing or anycast: GeoDNS returns different answers by resolver region, while anycast advertises the same IP from many PoPs so internet routing picks a nearby healthy location.
What's the difference between a CDN and a load balancer?
A CDN caches content at globally distributed edge locations to reduce latency and offload the origin; a load balancer distributes requests across a specific pool of backend servers, typically near the origin. They usually coexist rather than replace one another — see Load Balancer fundamentals for the backend-distribution layer.
How does a CDN protect the origin during a traffic spike?
By serving the vast majority of repeat requests from edge caches, so only the first request (or a small trickle of cache misses) ever reaches the origin — turning a potential origin overload into a non-event.
Design a CDN strategy for a global e-commerce site with both static assets and personalized checkout pages.
Long-TTL versioned URLs for static assets (images, JS, CSS); short micro-cache or no caching for personalized/checkout content marked private/no-store; origin shielding to absorb cache-miss thundering herds; edge WAF and TLS termination for security; automated purge as part of the deploy pipeline for CMS-driven pages.
Revision Notes
The condensed version of everything in the Fundamentals and Production Engineering chapters.
- 01CDN = globally distributed edge caching + global routing + origin protection, usually plus TLS termination and DDoS mitigation.
- 02Cache hit = served from edge instantly. Cache miss = edge fetches from origin, caches it, then serves it.
- 03TTL controls freshness (Cache-Control: max-age / s-maxage); invalidation (purge) forcibly removes stale content before TTL expiry.
- 04no-cache means 'cache but revalidate first', not 'don't cache' — no-store means 'never cache, anywhere'.
- 05Cache keys determine what counts as the 'same' request — unkeyed personalization inputs (cookies, auth headers) can leak private data between users.
- 06Origin shielding consolidates cache-miss traffic through a shield tier or designated PoP, preventing a thundering herd on the origin.
- 07CDN and load balancer are complementary, not competing — CDN decides if the origin is needed at all, load balancer decides which server handles it.
- 08GeoDNS = DNS-based routing, slower failover (DNS caching). Anycast = routing-based, faster than DNS caching but bounded by BGP convergence.
- 09Always cap TTL on error responses (5xx) to a short window to avoid caching an outage.
Quiz
Answer these from memory first; each question carries its short answer to check against.
Q1
Why doesn't a lower TTL always mean 'better' — what's the trade-off? Answer: A lower TTL gives fresher content but means more revalidations and origin fetches and a lower hit ratio. The right TTL is per asset: versioned files can live for a year, while a semi-dynamic page may need seconds.
Q2
What's the difference between no-cache and no-store, and why is the naming misleading? Answer: no-cache lets a cache store the response but requires revalidation before every reuse; no-store forbids storing it at all. The name sounds like no-store, which is why it misleads.
Q3
Why is anycast-based failover faster than GeoDNS-based failover? Answer: Anycast failover is a routing change (a PoP stops announcing the IP and BGP reroutes), so it avoids DNS caching delays, though it still depends on BGP convergence. GeoDNS failover waits for cached DNS answers to expire.
Q4
What is origin shielding, and what specific problem does it solve? Answer: A designated shield tier between the edge PoPs and the origin. It consolidates misses so a newly popular or cold object is fetched from the origin once rather than once per PoP, preventing a thundering herd.
Q5
Why can a request header or cookie that changes the response but is missing from the cache key (and from Vary) cause a serious security bug rather than just a performance issue? Answer: The cache stores the response under a key that does not include that input, so one user's personalised response can be served to others — a data leak or cache poisoning. An input that is in the key or Vary only costs hit ratio.
Q6
Name one scenario where you'd prefer versioned URLs over cache invalidation, and one where you'd prefer invalidation. Answer: Versioned URLs: hashed JS/CSS build artefacts, where a new deploy is a new key. Invalidation: a CMS-driven HTML page or a JSON config at a fixed URL that must update now.
Cheat Sheet
The whole module on one page.
WHAT: globally distributed edge cache network between users and an origin
WHY: latency (content near users) + origin protection (fewer requests reach origin)
CORE FLOW
request -> edge lookup -> HIT (serve) or MISS (fetch origin, cache, serve)
ROUTING
GeoDNS — DNS resolves by region, simple, slower failover
Anycast — same IP everywhere, routed to nearest PoP, failover bounded by BGP convergence
CACHE-CONTROL
public / private — who's allowed to cache
max-age / s-maxage — browser TTL / shared-cache (CDN) TTL
no-cache — cache but MUST revalidate first
no-store — never cache, anywhere
stale-while-revalidate — serve stale, refresh in background
stale-if-error — serve last-good copy if origin fails
CACHE KEY
path + query string by default
normalize/ignore tracking params to raise hit ratio
Vary header adds header-based dimensions — use sparingly
INVALIDATION
purge by URL / tag(surrogate-key) / wildcard
vs versioned URLs (cache-busting) — no purge needed, new deploy = new key
ORIGIN PROTECTION
origin shielding — a shield tier/PoP collapses many edge misses before origin
micro-caching — cache 'dynamic' responses for a few seconds
dynamic acceleration — optimized backbone, pooled origin connections, origin steering
SECURITY
TLS termination at edge
WAF + DDoS absorption via anycast + rate limiting
lock down origin IP to CDN ranges only
MONITORING
cache-hit ratio (headline metric)
origin request rate
edge latency p50/p95/p99 by region
5xx rate — edge vs origin, separately
CDN vs LOAD BALANCER
CDN decides IF the origin is needed at all
LB decides WHICH origin server handles it