CDNs - Deep Dive

Networking
15 / 21

CDNs cache your content at 300+ edge locations worldwide so users get sub-50ms responses instead of 500ms round trips to your origin.

ORIGINSERVERUS Edge (15ms)EU Edge (20ms)AS Edge (25ms)
SD blueprint: Edge Caching Architecture
The Analogy (Read This First)

Your warehouse is in Dallas. Shipping a package from Dallas to Tokyo takes 14 days. So you pre-position inventory in Tokyo, Singapore, London, and São Paulo. Now Tokyo customers get 1-day delivery from your regional warehouse. A CDN is the same idea for bits. Your origin server is the warehouse, PoPs (Points of Presence) are regional warehouses.

Deep Dive Analysis

A CDN is a geographically distributed network of servers (called edge nodes or PoPs - Points of Presence). When a user requests an asset, DNS routes them to the nearest edge node. If the edge has the content in cache (a HIT), it serves immediately. If not (a MISS), it fetches from your origin, caches, and serves.

What to cache: Static assets - images, CSS, JavaScript, videos, PDFs, font files. Also API responses with appropriate Cache-Control headers (public, max-age=3600). Do NOT cache: authenticated responses, dynamic personalized content, session data.

Cache-Control headers are the contract between your server and the CDN: `Cache-Control: public, max-age=31536000, immutable` = cache forever (for content-hashed assets like bundle.abc123.js). `Cache-Control: no-store` = never cache. `Cache-Control: public, s-maxage=0, stale-while-revalidate=86400` = CDN revalidates in background while serving stale.

Cache invalidation: When you update an asset, you need to purge the CDN cache or the old version will be served until TTL expires. Solutions: (1) Content-hash filenames (bundle.abc123.js → bundle.def456.js on change - never need to invalidate), (2) API calls to CDN purge endpoint (Cloudflare: instant, CloudFront: ~60s).

CDN as DDoS protection: A CDN absorbs volumetric DDoS attacks at the edge, far from your origin. Cloudflare has processed 71 million HTTP requests/second during DDoS events without impacting origin servers. Your 2-box origin could never survive that.

Key Bullets
  • Use content-hashed filenames for all static assets (built by Vite/webpack automatically).
  • Set immutable on versioned assets - browsers and CDNs will never re-check them.
  • S3 + CloudFront is the standard AWS static hosting pattern.
  • CDN Geography: Cloudflare 300+ PoPs, CloudFront 400+ PoPs, Fastly 60+ PoPs.
  • HTTP/2 multiplexing and HTTP/3 (QUIC) reduce connection overhead - CDNs support these.
Real-World Examples
Vercel: auto-CDN for all deployments (Edge Network built-in)Cloudflare: CDN + DDoS + WAF + DNS in oneAWS CloudFront: CDN with Lambda@Edge for serverless edge computeFastly: real-time CDN with Varnish-based edge logic

Curated Curation & Deep Insights

ScaleDojo Certified
Video Tutorial Pending

Our system architects are vetting high-quality, authorized video guides for CDNs - Deep Dive with zero third-party platform links.

Verification in Progress
Reading Material Pending

We are preparing premium, zero-competitor deep-dives for CDNs - Deep Dive. Authorized reading references will appear automatically.

Verification in Progress
ScaleDojo Logo
Initializing ScaleDojo