Lesson 1 of 16
26. CDNs

The picture to keep in your head

3 min read+10 XP

Every question below is answered twice: first in the warehouse, so you can picture it, then in the system, so you know exactly how it works. Each answer ends with a memory code to lock it in.

The picture to keep in your head

A biscuit company has one factory in Mumbai. If every shop in India had to send a truck to Mumbai for every carton, deliveries to Guwahati would take days and the factory gates would be jammed. So the company keeps warehouses in every big city. Shops collect from the nearest warehouse. The factory only ships to a warehouse when it runs out.

Every carton carries a label (which biscuit, which size) and a use-by date. When a batch turns out to be faulty, the company sends a recall notice and every warehouse pulls it off the shelves. And to stop fifty warehouses all phoning the factory at once for a new product, there's a regional depot in between that the warehouses call first.

That's a content delivery network (CDN): copies of your files kept close to your users, with clear rules about what's the same file, how long it stays fresh, and how to recall it.

Our running example: the bookstore's website. The origin servers are in Mumbai; readers are all over India and abroad. Pages load book covers, JavaScript and CSS bundles, book pages, and the new author-interview videos. Latency and traffic numbers are assumptions for practice.

In the warehouseIn the system
The factory in MumbaiThe origin server
A warehouse in every big cityEdge locations (PoPs)
Warehouses restock on demand vs ship in advancePull vs push CDN
Carton labels and use-by datesCache keys and Cache-Control headers
A recall noticePurging
A regional depot between warehouses and factoryOrigin shield
Warehouses that also assemble gift boxesDynamic content and code at the edge
A film delivered as a box of short reelsVideo segments (HLS, DASH)
A warehouse chain going on strikeWhen the CDN fails

the factory, city warehouses, labels, recalls and depot mapped to origin, PoPs, cache keys, purging and shield.

Figure: keep copies close to customers, label how long they stay fresh, and know how to recall them.