The CDN is the biggest cache you own
Most bytes a service sends are static, identical for every user, and never change.
What you will be able to do
- Decide which content is edge-cacheable
- Explain cache keys and why a wrong Vary header leaks data
- Design signed URLs for private media
- Describe byte-range delivery for video
What belongs at the edge
| Content | Cacheable? | Why |
|---|---|---|
| JS/CSS with a content hash in the name | Forever, immutable | A new build produces a new filename |
| Images and fonts | Long TTL | Rarely change; purge or rename on update |
| Public API JSON (catalog, trending) | Seconds to minutes | Shared by all users, tolerates slight staleness |
| HTML entry page | Short TTL or revalidate | Must reference the current asset hashes |
| User-specific API responses | No, unless keyed correctly | One user's response must never be served to another |
| Video segments | Long TTL | Immutable once encoded |
The naming convention is the trick that makes long TTLs safe: app.9f3c1a.js can be cached for a year, while index.html is fetched for a minute with revalidation. You deploy the new asset first, then the HTML that points at it.
Cache keys, purges, and the leak
The edge stores a response under a key built from host, path, and selected headers. If the response depends on something not in the key, the edge will serve one variant to everyone — occasionally one user's private data.
Vary: Accept-Encodingfor compressed variants; addAuthorizationorCookieif the body depends on identity.- Purge by URL is fast; purge-by-tag (surrogate keys) lets you invalidate everything referencing a product after an edit.
- A purge is not instant worldwide — assume tens of seconds and keep a versioned URL for anything critical.
- Set
Cache-Control: privateon anything user-specific so intermediaries refuse to store it.
Private media: sign, do not proxy
If media is private, a common mistake is streaming it through your application so you can check permissions. That puts every byte on your servers. Instead, the application checks permission once and issues a signed URL with an expiry; the CDN validates the signature and serves bytes directly.
GET /media/report.pdf?expires=1767225600&sig=8f14e45f... Edge checks: signature valid? not expired? path matches signature? Yes -> serve from cache or origin, never involving your API again
Video is a different problem
In an interview, mentioning a CDN is only useful if you say what it serves and what its cache key includes. "Static assets and public media at the edge with a long TTL and hashed filenames, HTML with a 60 second TTL, and private files through signed URLs" is a complete answer in one sentence.
Worth remembering
- Fingerprinted assets can be cached forever; HTML and API JSON need short TTLs or no caching.
- The cache key is the contract — anything that changes the response must be part of it.
- Private media should be a signed URL with an expiry, not a proxy that streams bytes through your service.
- Video is segmented and delivered by byte range, so a seek does not download the whole file.