Intermediate18 min readยท Topic 4.3

Content Delivery Networks (CDN)

Edge nodes, PoPs, cache hierarchy, CDN invalidation, major providers

๐ŸŒKey Takeaways

  • 1
    CDNs cache content at 200+ edge locations worldwide, reducing latency from ~150ms to ~5-20ms
  • 2
    Push CDN: you upload content to CDN; Pull CDN: CDN fetches from origin on first request
  • 3
    Cache hierarchy: Edge โ†’ Shield/Regional โ†’ Origin reduces origin load
  • 4
    CDNs 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

FeaturePush CDNPull CDN
How content arrivesYou upload to CDNCDN fetches from origin on first request
Cache controlFull control over what's cachedAutomatic based on Cache-Control headers
Best forRarely changing content, videoDynamic content, frequently updated sites
Origin loadZero (after push)First request per edge goes to origin
ComplexityYou manage uploadsCDN handles everything
ExamplesS3 + 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?