System Design Academy

Saving…

Lesson 4 of 9 in Module 40 of 54 lessons complete

CDNs

Module 4, lesson 4Concept10 min

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.

Nearby edges answer cached requests.

An Indian user reaches Mumbai and a UK user reaches London; either edge fetches missing content from the origin.

  1. Route the request

    DNS and network routing select a suitable edge, which may not be geographically nearest.

  2. Check the edge

    Return a reusable cached response when available.

  3. Load a miss

    Fetch from the origin, cache eligible content, and return it.

Two separate responses with different freshness needs.
HTTP
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.

Edges reduce announcement-day origin traffic.

Festival visitor → Nearby edge → Origin on miss.

The insight

A CDN absorbs global spikes.

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

Why does a user in Mumbai get your image faster through a CDN?
What lets you cache a file for a year yet still ship changes instantly?

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.

Try the quick check above whenever you feel ready.

Previous: Eviction & Invalidation