System DesignIntermediate12 min

CDNs & edge delivery

Serve content from points of presence near the user and control what gets cached, for how long, and how it is purged.

See it on the map

A content delivery network keeps copies of your responses in many locations close to users, so most requests never travel to your origin server. It cuts latency, absorbs traffic spikes and protects the origin. Static files are the obvious fit, and many dynamic pages can be cached for seconds or minutes with the same benefit.

You steer it with headers. Cache-Control sets how long a response is fresh, and for how long a stale copy may be served while a fresh one loads. The cache key, usually the URL plus selected headers, decides which requests share an entry, so varying on too many headers destroys the hit rate. Fingerprinted file names such as app.3f9a.js can be cached for a year because a new build changes the name.

Purging is the hard part. Prefer short lifetimes and versioned URLs to relying on purges. Never cache responses that depend on a user's session under a shared key. For private content use signed, expiring URLs, and consider an origin shield, a middle cache tier that reduces load on the origin when many edge locations miss at once.

Key points

  • A CDN cuts latency and shields the origin by serving from nearby caches.
  • Cache-Control and the cache key decide what is shared and for how long.
  • Fingerprint static assets and cache them for a long time.
  • Do not cache per-user responses under a shared key.

Answer these out loud

  1. 1A product page changes price twice a day and is read 5,000 times a second. Choose cache headers and a purge strategy.
  2. 2Why can adding a Vary header on a cookie make a CDN almost useless?

Use this from an agent

Any MCP client, including Grok, can read this lesson. See how to connect.

REST
curl https://engineeros-delta.vercel.app/api/v1/topics/cdn-and-edge-delivery