Skip to content
System Design Fundamentals

Lesson 8 of 12 · 16 min

x
8/12

Lesson position in the course — not completion. Use Mark Complete to track finished lessons (saved in this browser).

Content Delivery Networks

A CDN is a globally distributed network of edge servers that cache content close to users. Instead of every request crossing the world to your origin server, a user in Tokyo hits a CDN node in Tokyo and gets a cached response in milliseconds. This reduces latency for static assets and offloads traffic from your origin.

Modern CDNs do more than cache files. Edge compute (Cloudflare Workers, Lambda@Edge, Vercel Edge Functions) runs code at CDN nodes — A/B testing, authentication, personalisation — without a round trip to origin. Dynamic content can be cached at the edge too using short TTLs and stale-while-revalidate: serve the cached version instantly, refresh it in the background.

Before
No CDN — every user hits origin
1User (Tokyo) → Origin Server (US East) → response2Round-trip latency: often 100ms+ cross-region (measure yours)3All traffic hits origin — static and dynamic4Image assets re-fetched on every cold load
After
CDN — assets and short-lived API responses cached at edge
1User (Tokyo) → CDN Edge (Tokyo) → low double-digit ms on cache hit (typical; measure)2 3// Immutable assets — cache forever at edge4Cache-Control: public, max-age=31536000, immutable5 6// API responses — cache briefly, serve stale while refreshing7Cache-Control: s-maxage=60, stale-while-revalidate=30

Check your understanding

  • What does a CDN primarily optimize?Show answer

    Answer

    Latency and origin load by serving cached content from edge locations closer to users — for cacheable responses.
  • What should usually not be cached at the shared CDN edge?Show answer

    Answer

    User-specific private responses (my orders, my session) unless carefully varied and authorized.
  • What does stale-while-revalidate do?Show answer

    Answer

    Serve a cached response immediately while refreshing in the background within policy limits.
Previous

Progress is saved in this browser.

Next Lesson