CDNs
Definition
CDN
- In plain English
- A CDN, or content delivery network, is a worldwide network of servers that caches your content close to users.
- Think of it like
- It is like a chain of local bookshops stocking a bestseller so nobody has to order from the publisher's warehouse.
Edge server
- In plain English
- An edge server is a CDN server located near users that answers requests from its cache.
- Think of it like
- It is like your local branch of the bookshop chain.
Why it exists
A distant user waits for requests to cross continents. A long ocean route can add roughly 100 ms of round-trip delay.
A nearby cache might answer in 10–20 ms. Actual delays depend on distance, routing, and network conditions.
How it works
Origin
- In plain English
- The origin is your own server that holds the original content the CDN copies from.
- Think of it like
- Like the publisher's central warehouse.
Cache-Control header
- In plain English
- Cache-Control is an HTTP header that tells browsers and CDNs whether and how long they may cache a response.
- Think of it like
- Like a "display until" sticker on a shop poster.
Purge
- In plain English
- A purge tells the CDN to drop cached copies immediately.
- Think of it like
- Like recalling a misprinted book from every branch.
An Indian user reaches Mumbai and a UK user reaches London; either edge fetches missing content from the origin.
- Route the request
DNS and network routing select a suitable edge, which may not be geographically nearest.
- Check the edge
Return a reusable cached response when available.
- Load a miss
Fetch from the origin, cache eligible content, and return it.
HTTP/1.1 200 OK
Content-Type: image/png
Cache-Control: public, max-age=31536000, immutable
[versioned image bytes]
HTTP/1.1 200 OK
Content-Type: text/html
Cache-Control: public, max-age=60
[public page HTML]- Use a new file name when image bytes change, such as logo.3f9a2c.png.
- Update the page to reference that new URL.
- A purge takes time to reach edges and does not remove copies already stored in browsers.
Examples
Music festival
Two million visitors arrive worldwide within an hour of the line-up announcement. Edges serve cached images and the public page.
Two million visitors arrive within an hour. With a warm cache, many image and public page requests stay at the edges.
Festival visitor → Nearby edge → Origin on miss.
The insight
A CDN absorbs global spikes.
Flashcard app
Deck images and audio use versioned file names with a one-year lifetime. Changed content gets a new name, avoiding a purge.
Publish the new file first, then update the deck to reference it. Existing pages can continue using the old file.
before: /decks/cells.3f9a2c.png
after: /decks/cells.8b2d10.png
cache lifetime: 31536000 secondsThe insight
Versioned names make long caching safe.
Wildfire alerts
The evacuation map uses a 60-second edge lifetime. When the fire line moves, the publisher requests a purge immediately.
The purge still needs time to spread. Browser copies can also remain until their own freshness period ends.
Treat the map as a dated public summary. Urgent instructions need a separately verified delivery path with an explicit freshness limit.
The insight
Short lifetimes plus purges keep urgent content fresh.
Trade-offs
Pros
- Lower delay for distant users.
- Less origin traffic.
- More capacity for global spikes.
- Some protection against traffic floods.
Cons
- Delivery and storage cost money.
- Copies remain until expiry or completed purge.
- Private responses need careful controls.
Use when
- Public pages reach distant users.
- Versioned images and audio change rarely.
Avoid when
- Avoid shared caching of private user responses.
- Avoid relying on cached maps for immediate evacuation instructions.
Quick check
Takeaways
- A CDN caches content near users.
- A reusable edge copy avoids an origin request.
- Versioned URLs support long file lifetimes once pages reference the new version.