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
26.2 What are edge locations (PoPs)?
3 min read+10 XP
In the warehouse: The warehouses sit in big cities, near highways, where most shops can reach one quickly. A shop goes to whichever is nearest and open.
In the system: A CDN runs points of presence (PoPs): data centres in many cities, each with cache servers, connected to local internet providers. Big CDNs run hundreds of them worldwide.
How a reader reaches the nearest one:
- Anycast: many PoPs announce the same IP address; the internet's routing (BGP) delivers each user's packets to a nearby one (Chapter 4 touched on this for DNS).
- DNS-based steering: the CDN's DNS answers with the IP of a good PoP for the user's location and current load (Chapter 4).
Inside a PoP:
- Many cache servers share the work, often using consistent hashing (Chapter 28) so each object lives on one or two servers in the PoP, instead of every server caching everything.
- Hot objects sit in memory, the rest on SSDs.
- A miss goes to the origin, or to a shield first (26.6).
Things to know:
- Hit ratio varies by PoP. A small-city PoP sees less traffic, so more of its requests are first-time misses.
- Caches evict. Rarely requested files (an old book's cover) may be dropped and fetched again later; "cached for a year" means "allowed to be", not "guaranteed to be".
Memory code: "A warehouse in every city; the road takes you to the nearest."