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: 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:
| Mode | How it works | Cost |
|---|---|---|
| Pull CDN | The edge fetches from the origin the first time someone asks | The first request is slower |
| Push CDN | The origin uploads to the CDN when the file changes | You 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.