The problem in one picture
A cricket highlights page goes viral at 10 PM. Two million people in India open it in ten minutes. Your origin server sits in one region and can comfortably serve a few thousand requests a second. Without a CDN, it falls over. With a CDN set up badly, it still falls over, because every edge location asks the origin for the same file at the same moment.
A CDN is a cache that lives in hundreds of cities. It only helps if it answers three questions well: what counts as "the same" request, how long a copy stays good, and who is allowed to bother the origin when a copy runs out.

Question 1: what counts as the same request?
The CDN stores responses under a cache key. Two requests with the same key get the same stored copy. Cloudflare's default key is the full URL, including the query string (Cloudflare docs).
That default bites people. /logo.png?utm_source=newsletter and /logo.png?utm_source=twitter are two different keys, so the same logo is fetched from your origin twice and stored twice. Multiply by every campaign tag and your hit rate quietly drops.
The fix is to decide what really changes the response. Tracking parameters don't, so drop them from the key. Language or device type might, so add those on purpose instead of letting every header vary the key.
Question 2: how long is a copy good?
The origin decides this with the Cache-Control header. max-age=600 means "fresh for 600 seconds". While fresh, the edge serves the copy without asking anyone.
The interesting part is what happens at second 601. A plain cache treats the copy as stale and makes the next viewer wait while it refetches. Two extensions from RFC 5861 change that:
stale-while-revalidate=30: for 30 seconds after expiry, keep serving the stale copy instantly and refetch in the background.
stale-if-error=86400: if the origin returns a 500, 502, 503 or 504, keep serving the stale copy instead of the error.

The first one hides refetch latency. The second one turns an origin outage into "slightly old content" instead of an error page, which is often the most valuable line in your whole config.
Question 3: who gets to bother the origin?
Now the viral page again. The copy expires at the same time in 300 edge locations. Each one misses and each one calls the origin. That's a stampede, and it's caused by the CDN's own size.
Tiered caching fixes it by putting the edges in a hierarchy. Cloudflare splits its data centers into lower tiers and upper tiers: a lower tier that misses must ask an upper tier, and "only the upper-tier can ask the origin for content" (Cloudflare Tiered Cache). Three hundred misses become a handful of origin requests.
This is the same idea as the lease from the Cache Writes post on Facebook's memcache: when many readers miss at once, let one of them fetch and make the rest reuse its answer.
What changes when content changes
TTL is the plan; purging is the escape hatch. Two common approaches:
Versioned URLs. Put a content hash in the file name, like
app.3f9a1c.js, and cache it for a year. A new build means a new URL, so nothing needs purging. This is the standard for JS, CSS and images.Purge on change. For URLs that can't change, like
/product/123, keep the TTL short or call the CDN's purge API when the data changes.
Mixing them up is the classic bug: a long TTL on /index.html that points at old versioned files, so users get yesterday's app for a day.
How to choose in an interview
When a design has static or read-heavy content, say these four things out loud:
What is the cache key? Strip what doesn't change the response.
What is the TTL, and is the content versioned? Long for versioned assets, short for anything mutable.
What happens when the origin is slow or down? Name stale-while-revalidate and stale-if-error.
What stops a stampede on the origin? Name tiered caching, or request collapsing at the edge.
Success criteria: check yourself
Pick a setup for each, then compare with the answers below:
A product image at
/img/123.jpgthat is replaced when the seller uploads a new photo.The live score widget on that cricket page, updated every few seconds.
A news site that must stay up even when its CMS is down.
You've got it if you chose: (1) a versioned URL like /img/123-v7.jpg with a long TTL, because then a new photo is just a new key; (2) a short max-age of a second or two with stale-while-revalidate, so the edge absorbs the read load and nobody waits on refetches; (3) stale-if-error with a long window, so the last good page keeps serving during the outage.
Interview angle
Saying "put a CDN in front" is an L4 answer. Naming the cache key, the TTL and how changes reach users is L5. Naming the origin-protection story (tiering, stale-if-error) and what you'd watch, such as edge hit ratio, origin request rate and the share of responses served stale, is L6.
Next up
Next Thursday: Idempotency keys, and how Stripe makes it safe to retry a payment when the network drops halfway through.
