Content Delivery Networks

How CDNs bring content close to users — edge caching, push vs pull, cache keys and invalidation, dynamic acceleration, edge compute, and security benefits.

Intermediate 3 min readLesson 7 of 20

A content delivery network is a global network of servers (points of presence, PoPs, or "edges") that cache and serve content close to users. Because latency is bounded by distance (Latency), serving a file from 20 km away instead of 8,000 km away makes pages dramatically faster — and offloads most of the traffic from your servers.

~10 ms~10 msmiss onlymiss onlyUser in TokyoUser in ParisTokyo edgecacheParis edgecacheOriginus-east servers / S3

How a request reaches the edge

Your domain points to the CDN (a CNAME or the CDN's name servers). The CDN steers each user to a nearby, healthy PoP using anycast (the same IP announced everywhere, BGP picks the nearest) or GeoDNS. The edge serves cached content or fetches it from your origin on a miss, often through intermediate shield tiers so the origin sees one request per object rather than one per PoP.

What CDNs serve

ContentCaching
Static assets: JS, CSS, fonts, imagesCache for a long time with versioned filenames
Media: video segments, downloadsLarge files close to users
Whole HTML pagesFor static sites or with short TTLs
API responsesPublic, cacheable GETs with short TTLs
Dynamic, personalised contentNot cached, but still accelerated (see below)

Pull vs push

  • Pull CDN — the edge fetches from the origin on the first request, then caches. Zero setup; the first user per PoP pays the miss. The usual choice.
  • Push CDN — you upload content to the CDN in advance. Good for large files or predictable releases.

Controlling the cache

The origin controls caching with HTTP headers:

HTTP
Cache-Control: public, max-age=31536000, immutable          # fingerprinted assets
Cache-Control: public, s-maxage=60, stale-while-revalidate=300   # CDN caches 60 s
Cache-Control: private, no-store                             # personalised: never at the edge
Vary: Accept-Encoding
  • s-maxage applies only to shared caches (CDNs); max-age to browsers too.
  • stale-while-revalidate serves the old copy instantly while refreshing in the background.
  • The cache key (usually host + path + selected query parameters and headers) decides what counts as "the same" object. Including unnecessary parts (random tracking parameters, cookies) destroys the hit rate.

Invalidation

Beyond caching

  • Dynamic acceleration — even uncacheable requests benefit: TLS terminates near the user (saving round trips), and the CDN keeps warm, optimised connections to your origin over its private backbone.
  • Security — absorbs DDoS attacks with enormous capacity, provides a WAF, bot management and TLS; hides your origin's IP.
  • Image and video optimisation — resizing, format conversion (WebP/AVIF) and adaptive streaming at the edge.
  • Edge computing — run code at the PoPs (Cloudflare Workers, Fastly Compute, Lambda@Edge, Vercel/Netlify edge functions): auth checks, A/B tests, redirects, personalisation, even full applications with edge databases (Serverless & edge).

Metrics that matter

  • Cache hit ratio (by requests and by bytes) — aim for 90%+ on static content.
  • Origin offload — the share of traffic that never reaches your servers.
  • Time to first byte from the edge, and error rates per PoP.
Key takeaways
  • CDNs cache content in PoPs near users, cutting latency and origin load.
  • Requests reach the nearest PoP via anycast or GeoDNS; misses go to the origin (via shields).
  • Control caching with Cache-Control (max-age, s-maxage, stale-while-revalidate) and careful cache keys.
  • Fingerprint static assets instead of purging.
  • CDNs also accelerate dynamic traffic, absorb DDoS, and run code at the edge.