Caching & Content DeliveryIntermediate14 min read2 questions

CDNs and Edge Caching

The cheapest performance improvement available to any global product. How CDNs work, the HTTP headers that control them, and how to invalidate content across hundreds of locations.

Covers: How a CDN works, cache-control headers, ETags, purging, push vs pull, edge compute, origin shielding

A CDN is a cache with geography. It solves a problem no amount of server optimisation can touch: the speed of light. If your origin is in Virginia and your user is in Singapore, the round trip is ~230 ms no matter how fast your code is. A PoP in Singapore turns that into ~10 ms.

Filter
0/2 mastered
BeginnercdnedgecachingAsked at Cloudflare, Netflix

30-second answer

A CDN is a network of points of presence worldwide. DNS or anycast routing directs a user to the nearest PoP; if that PoP has a fresh copy it serves it in tens of milliseconds, and if not it fetches from origin, caches it, and serves subsequent requests locally. Put static assets, images, video, downloads and cacheable API responses through it. Keep personalised, authenticated and rapidly changing content on the origin - or use edge compute so the dynamic part is assembled near the user while the static shell still comes from cache.

Intermediatehttpcdncache-controlAsked at Cloudflare, Shopify

30-second answer

`Cache-Control` is the primary control: `max-age` for browsers, `s-maxage` for shared caches, `public` versus `private`, `no-store` to forbid caching entirely, and `stale-while-revalidate` to serve stale content while refreshing in the background. `ETag` and `Last-Modified` enable revalidation, letting the server return a 304 with no body. For invalidation, the best strategy is to avoid it: use content-hashed immutable URLs so a new version is a new URL. When you must purge, prefer surrogate keys - tag responses and purge by tag - over purging URLs one at a time.

Showing 2 of 2 questions for cdn-and-edge-caching.

Check your understanding

4 questions · no sign-up, nothing stored

0/4 answered
Question 1

1.Which header combination is correct for a JavaScript bundle whose filename contains a content hash?

Question 2

2.What does `stale-while-revalidate=600` do?

Question 3

3.Why does origin shielding matter after a global purge?

Question 4

4.You must remove a leaked document from all caches immediately. What is the reliable approach?

Hands-on challenge

Build it - this is what you talk about in a deep-dive round.

Design the caching layer for a news site

A news site serves 50 million page views a day globally. Articles are updated after publication, and the homepage changes every few minutes.

Requirements

  • Specify Cache-Control for: hashed assets, images, the homepage, an article page, and a logged-in user's page.
  • Design the cache key, listing which query parameters are included and which are stripped.
  • Define the surrogate-key scheme and show how correcting one article purges every page that references it.
  • Explain how a breaking-news homepage update propagates in under 10 seconds without hammering origin.
  • Estimate the origin QPS with and without the CDN, assuming a 97% offload rate.

Stretch goals

  • Serve a personalised header on a cached page using edge compute, and state the hit-rate impact.
  • Design the failure behaviour when the origin is completely down, using `stale-if-error`.