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.3 Pull vs push CDN: what's the difference?
3 min read+10 XP
In the warehouse: Some warehouses restock on demand: a shop asks for a product, and if the shelf is empty, the warehouse orders it from the factory and keeps some on hand. Others are stocked in advance: the factory ships the full range to every warehouse before launch day.
In the system:
Figure: pull is easy and caches what's popular; push avoids cold misses but you manage the files.
- Pull CDN (the common choice): you point the CDN at your origin. On a miss, the edge fetches the file from the origin, caches it according to its headers, and serves it. Zero upload work, and only popular files take up space. The first request per PoP is slower.
- Push CDN: you upload files to the CDN's storage when you publish them (often object storage like S3 behind the CDN, Chapter 11). Requests are served from there, so the origin isn't involved at all. No cold misses from the origin, but you manage uploads, versions and deletions.
In practice many setups are a mix: static assets and covers sit in object storage that the CDN pulls from, and big launches can be pre-warmed by requesting key files through the CDN before the traffic arrives.
Memory code: "Restock when asked, or ship before launch day."