Skip to the page

Design building blocks · core

What to serve from a CDN

A CDN keeps copies at edge servers near users. Serve static and public content from it, never personal content, and use versioned file names instead of purges.

The notes

What you must know

  • Edge servers near users keep copies. A miss goes to a regional tier or origin shield, then the origin. This cuts latency and origin load, absorbs attacks and ends TLS close to the user.
  • Serve images, JS and CSS with hashed file names (long max-age, immutable), video segments, and public pages or API responses that are the same for everyone (short TTL plus stale-while-revalidate).
  • Do not cache personalised pages, cart, checkout or anything with auth cookies, unless the cache key covers what varies. Use Cache-Control private or no-store. Never cache a response with Set-Cookie.
  • Removal: purge by path or tag, but better use versioned URLs that never need a purge. Do not purge the whole CDN on every deploy.
  • Private files use signed URLs or signed cookies with a short expiry.
  • Images: resize and convert to WebP or AVIF at the edge for slow networks. Check hit ratio by region and CDN coverage in your cities.
  • Query parameters must be part of the cache key correctly, or users see wrong pages.

The red pen

Common traps: mistake → fix

  • Mistake: A CDN is only for images

    Fix: it also serves public pages and API responses.

  • Mistake: Purge everything on each deploy

    Fix: use hashed file names.

  • Mistake: Cache logged-in pages with a long TTL

    Fix: users may see someone else data.

Easy to hard

Questions interviewers ask, easy to hard

  1. What do you serve from a CDN and what not?
  2. How do you update a file that is cached on the CDN?
  3. How do you serve private files through a CDN?
  4. How do you serve users on slow networks?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview