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.
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.
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
| Content | Caching |
|---|---|
| Static assets: JS, CSS, fonts, images | Cache for a long time with versioned filenames |
| Media: video segments, downloads | Large files close to users |
| Whole HTML pages | For static sites or with short TTLs |
| API responses | Public, cacheable GETs with short TTLs |
| Dynamic, personalised content | Not 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:
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-Encodings-maxageapplies only to shared caches (CDNs);max-ageto browsers too.stale-while-revalidateserves 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.
- 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.