26. CDNs
1
The picture to keep in your head2
26.1 Why use a CDN?3
26.2 What are edge locations (PoPs)?4
26.3 Pull vs push CDN: what's the difference?5
26.4 How do cache keys and headers work?6
26.5 How does purging work?7
26.6 What is an origin shield?8
26.7 Can the CDN handle dynamic content?9
26.8 How do CDNs deliver video (HLS, DASH)?10
26.9 What happens when the CDN fails?11
Memory card and where the analogy breaks12
Practice: five levels13
Interview questions14
Solutions15
Sources16
Code lab26. CDNs
Memory card and where the analogy breaks
3 min read+10 XP
The memory card (tear this page out)
| # | Question | Memory code |
|---|---|---|
| 26.1 | Why a CDN? | Stock it near the shop, and the factory can rest |
| 26.2 | Edge locations? | A warehouse in every city; the road takes you to the nearest |
| 26.3 | Pull vs push? | Restock when asked, or ship before launch day |
| 26.4 | Cache keys and headers? | One label per product, and a use-by date on every carton |
| 26.5 | Purging? | Recall by product or by batch, but better to change the label than chase the cartons |
| 26.6 | Origin shield? | Warehouses call the depot; only the depot calls the factory |
| 26.7 | Dynamic content? | Cache the shared part for seconds, and do the small jobs near the customer |
| 26.8 | Video segments? | Cut the film into reels, in several qualities, and let the player pick reel by reel |
| 26.9 | CDN failure? | If the warehouses strike, have a second chain, and keep old stock you can still sell |
The whole chapter in one line: Serve copies from a nearby edge, define "the same file" carefully, label freshness with Cache-Control, version instead of purging, shield the origin, cut video into segments, and plan for the CDN itself failing.
Where the analogy breaks
- A biscuit carton is the same for every shop. Web responses can be personal, and a CDN that treats a personal page like a carton hands one user's data to another.
- A recall reaches every warehouse but not the biscuits already in people's kitchens. A purge can't reach browsers' caches either, which is why browser TTLs need care.
- Opening a new warehouse takes months. A CDN can route you to another city in milliseconds, which is why a CDN's mistakes also spread worldwide in seconds.
Quick check
Five questions on this chapter. Pick an answer, then check it.
quiz