Skip to content
All writing ‹ Part 01 of 18 · A Cache Is a Chain, Not a Box
Engineering · 3 min read

What a CDN Is

A CDN is a group of edge servers near users. How pull and push modes get files to the edge, and why cache rules decide whether the edge copy is fresh.

A CDN is a group of edge servers placed around the world. A user asks the nearest edge for a file, so the request does not go back to the origin every time.

In interviews, I only said “add a CDN layer and it gets faster.” But why is it faster? And how do files get to the edge? This was the first step of my chase.

Origin server(one location) Edge server(Tokyo) Edge server(Los Angeles) Edge server(Frankfurt) Edge server(Singapore) The user gets the file from the nearest edge
One origin feeds many edge servers, and each user reads from the nearest one.
  • Origin: the place where the file really lives, for example a storage bucket or an application server.
  • Edge server: a CDN server placed near the user. It keeps a copy of the file.
  • TTL (time to live): how long the edge can keep the copy. When the time ends, the edge must ask the origin again (Cache Freshness: Fresh, Stale, and 304).

Two modes decide how a file reaches the edge:

ModeHow it worksCost
Pull CDNThe edge fetches from the origin the first time someone asksThe first request is slower
Push CDNThe origin uploads to the CDN when the file changesYou must manage the upload yourself

The CDN I use at work is in pull mode. So cache rules decide whether the edge has a copy and whether the copy is fresh. The rest of this series chases those rules.

A CDN is fast for a simple reason: the file is close to the user. The hard part is deciding when to replace the copy.

Sources: ByteByteGo: How does CDN work, System Design Primer: CDN

Related: One HTTP Request, Cache Freshness: Fresh, Stale, and 304, CDN Terms on One Page. Or go back to the series overview.

↑↓ navigate ↵ open esc close