Steven's Knowledge

CDN

Content Delivery Networks - global caching, edge POPs, image optimization, DDoS protection, and pricing

CDN

A Content Delivery Network is a fleet of servers spread around the world that cache and serve your content from the location closest to each user. The basic value: a user in Tokyo doesn't have to wait for bytes to fly from your origin in Virginia.

What a CDN Does

FeatureWhy it matters
Geographic cachingServe cached content from a nearby POP — 10-100× lower latency than origin
TLS termination at the edgeHTTPS handshake near the user; faster page loads
HTTP/2, HTTP/3, BrotliModern transport without you upgrading your origin
DDoS absorptionA huge attack hits the CDN, not your origin
Bot mitigation / WAFBlock scrapers and exploit attempts at the edge
Image / video optimizationResize, recompress, transcode on the fly
Edge computeRun logic at the POP (see Edge Functions)
Origin offloadMost traffic never reaches your servers

The lift isn't just speed — it's cost. A well-tuned CDN serves 95%+ of bytes from cache, your origin shrinks accordingly.

The Players

CDNNotes
CloudflareHuge POP network, generous free tier, integrated DNS/WAF/edge functions
FastlyDeveloper-friendly, fast purge, VCL programmability, real-time logs
AWS CloudFrontDeeply integrated with AWS; pricing per region
Google Cloud CDNTied to GCP Load Balancer; HTTP/3-first
Azure CDN / Front DoorFront Door is the modern combined CDN + WAF + LB
AkamaiEnterprise heavyweight; broad feature set
Bunny.netCheap, fast, simple — popular for static sites
KeyCDN, CDN77Smaller commercial options
jsDelivr / unpkgPublic CDNs for open-source JavaScript packages

For new projects: Cloudflare or Fastly for full-featured needs, Bunny.net when cost matters more than features.

How a Request Flows

   User in Tokyo


   ┌─────────────┐
   │  Tokyo POP  │  ← serves from cache if available
   └──────┬──────┘
          │ on cache miss

   ┌──────────────────────┐
   │ Shielding tier (opt) │  ← reduces origin hits across all POPs
   └──────┬───────────────┘
          │ on cache miss

   ┌──────────────┐
   │   Origin     │  ← your servers
   └──────────────┘

The first user in Tokyo pays the full round trip to origin. The next 1000 users get the cached response from Tokyo at ~5 ms.

Learning Path

What a CDN Doesn't Do

MisconceptionReality
"CDN = faster for everything"Dynamic per-user content doesn't cache; CDN adds a hop
"I can stop worrying about origin capacity"First requests still hit it; bypass + purge floods can too
"CDN means I'm DDoS-protected"Only if you enforce it; misconfigured origins are still reachable
"Set Cache-Control once and forget"Cache headers, purge strategy, vary-on-cookie all need tuning

A CDN is a caching layer with security and edge features bolted on. Most of the value comes from caching done right — see Caching Strategies.

Static vs Dynamic vs Personalized

Three traffic patterns, three approaches:

TrafficCacheable?How to handle
Static assets (JS, CSS, images, fonts)FullyLong Cache-Control: public, max-age=31536000, immutable; hash in filename
Public dynamic (product pages, articles)MostlyShort TTL + purge on update, or stale-while-revalidate
Per-user (account dashboard, cart)Almost never at the CDNMark Cache-Control: private; consider per-user at-edge KV
Per-cookie variationsCarefullyVary by a small set of "buckets" not raw cookies

The classic mistake is caching responses keyed by raw cookies — the cache fragments into millions of entries that mostly never get hit again.

A CDN is upstream of your API Gateway. The CDN handles geography, caching, and DDoS at the edge; the gateway handles routing, auth, and rate limits per app. They compose.

On this page