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.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe 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
- What do you serve from a CDN and what not?
- How do you update a file that is cached on the CDN?
- How do you serve private files through a CDN?
- How do you serve users on slow networks?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.