๐Key Takeaways
- 1CDNs cache content at 200+ edge locations worldwide, reducing latency from ~150ms to ~5-20ms
- 2Push CDN: you upload content to CDN; Pull CDN: CDN fetches from origin on first request
- 3Cache hierarchy: Edge โ Shield/Regional โ Origin reduces origin load
- 4CDNs handle DDoS absorption, TLS termination, and image optimization
Bringing Content Closer to Users
A CDN is a globally distributed network of servers that caches content at 'edge' locations close to end users. Instead of every request traveling to your origin server in us-east-1, the CDN serves it from a Point of Presence (PoP) that might be in the same city as the user.
CDNs are essential for any globally distributed application. Without a CDN, users in Australia accessing a US-based server experience ~200ms latency just from the speed of light. With a CDN, the same content is served from Sydney in ~5ms.
CDN Impact
200+
CDN edge locations
~5ms
Edge cache latency
~200ms
Without CDN (cross-continent)
40x
Latency improvement
Push vs Pull CDN
| Feature | Push CDN | Pull CDN |
|---|---|---|
| How content arrives | You upload to CDN | CDN fetches from origin on first request |
| Cache control | Full control over what's cached | Automatic based on Cache-Control headers |
| Best for | Rarely changing content, video | Dynamic content, frequently updated sites |
| Origin load | Zero (after push) | First request per edge goes to origin |
| Complexity | You manage uploads | CDN handles everything |
| Examples | S3 + CloudFront (push) | Cloudflare, Fastly (pull) |
โ
Cache Invalidation for CDNs
CDN cache invalidation is slow (propagates to all 200+ edges). Better approach: use immutable content โ append a hash to filenames (main.a3b4c5.js). New deploy = new filename = automatic cache bypass. This is what Next.js and Webpack do with content hashing.
Advantages
- โขDramatic latency reduction for global users
- โขDDoS protection via distributed infrastructure
- โขReduces origin server load by 80-95%
Disadvantages
- โขCache invalidation is slow and complex
- โขAdds cost ($0.01-0.10 per GB)
- โขDynamic/personalized content is harder to cache
๐งช Test Your Understanding
Knowledge Check1/1
How does a Pull CDN get content?