Skip to main content
Cloud basicsLesson 10 of 17

How a CDN Serves a Request

A CDN (content delivery network) keeps copies of your responses in many edge locations close to users. Follow one file from the first miss to a cache hit, then see what goes wrong after a deploy and with private pages. The basic web request is in When You Type an Address.

Request/app.3f9a.js
Cache—
Age—
Origin load—
Edge location (PoP)Your originUserBrowser in SeoulDNSCDN name serversEdge serverTLS · cache lookupEdge cacheKey → responseOrigin shieldRegional cacheOriginBucket or LBwww.example.com?
RequestResponse / reportWatchAppears in a later step

What you will learn

  • How DNS or anycast sends users to a nearby edge
  • Cache key, hit and miss, and the origin fetch
  • Cache-Control max-age and s-maxage decide how long
  • Revalidation with ETag and 304 Not Modified
  • Versioned file names beat purging after a deploy
  • Keeping private responses out of a shared cache

Response headers to read​

HeaderExampleWhat it tells you
Cache-Controlpublic, max-age=31536000, immutableWho may store the response and for how long. s-maxage is for shared caches only. private and no-store keep it out of the CDN
Age120Seconds the response has been in a cache. Missing or 0 usually means it came fresh from the origin
ETag"5d8c72a5"Version tag of the content. Used in If-None-Match to get 304 Not Modified
Last-ModifiedTue, 24 Nov 2026 03:10:00 GMTOlder way to revalidate, with If-Modified-Since
VaryAccept-EncodingRequest headers that are part of the cache key. Vary: * or many values cut the hit rate
Hit header (vendor-specific)X-Cache: Hit from cloudfront, cf-cache-status: HITThe CDN's own verdict: HIT, MISS, EXPIRED, BYPASS and so on. The name and values differ by vendor

Try it yourself​

dig +short www.example.com # A CNAME to the CDN's hostname means the CDN is in front
curl -sI https://<your-site>/<file> | grep -iE 'cache-control|^age|etag|x-cache|cf-cache-status' # 1st call: likely MISS
curl -sI https://<your-site>/<file> | grep -iE 'cache-control|^age|etag|x-cache|cf-cache-status' # 2nd call: HIT, Age grows
curl -sI -H 'If-None-Match: "<etag from above>"' https://<your-site>/<file> | head -1 # 304 if unchanged
curl -sI https://<your-site>/account | grep -i cache-control # Personal pages should say private or no-store

Check yourself

  1. You deploy a new app.js under the same name, and some users still get the old script. What fix does the lesson recommend so deploys need no purge?
  2. The cached /account page showed one user's name to another user. What should the origin send for this page?
  3. /index.html has max-age=60. After 60 seconds a user asks for it, and the file has not changed at the origin. What does the edge do?

Further reading: HTTP caching (MDN) · RFC 9111: HTTP Caching · Cache-Control (MDN) · When You Type an Address · How Object Storage Works