← Back to all articles

How a CDN Brings Content Close to You

NetworkBeginner

Core idea

A CDN spreads edge nodes worldwide, caching static content near users. The origin serves once; afterwards responses come from nearby, cutting latency and origin load.

How a request reaches the edge

  1. The user hits cdn.example.com; DNS returns the nearest edge IP by location;
  2. The edge serves from cache on a hit;
  3. On a miss it fetches from the origin, caches, then returns.

Two cache actions

ActionEffect
PurgeDrop old cache so the next request re-fetches the new version
PrefetchPush content to edges proactively to avoid a cold first visit

What belongs on a CDN

  • Good: images, scripts, styles, fonts, video -- static assets;
  • Bad: dynamic content with private user data (it would leak to others); mark those Cache-Control: private or serve from origin.