CDN caching for static assets and cacheable responses
corebeginnerA CDN (content delivery network) is a globally distributed set of caching servers, positioned close to end users geographically, that cache and serve content on behalf of an origin server. It removes both the network distance and the origin's repeated-serving cost for anything that can be safely cached — classically images, CSS and JS, but also API or page responses that are the same for many users.
Think of it as
An origin server is a single central warehouse; a CDN is a network of local pop-up stores near where customers actually are. A customer who wants something the local store already stocks gets it immediately, without a truck driving all the way from the warehouse. Only when the local store doesn't have an item does it need to ask the warehouse — and once it does, it stocks that item locally for the next customer.
What we're doing: Show the latency difference a CDN edge cache makes for a globally distributed user base.
- 5
- This is the pure network-distance cost a CDN exists to remove — nothing to do with the origin being slow, just physical distance.
- 10
- The edge cache serving locally is what collapses that 180ms round trip down to a few milliseconds.
Why this works: CDN latency wins come almost entirely from network distance, not server processing speed — a perfectly fast origin still can't beat the speed of light for a user on the other side of the planet, which is exactly the problem geographic distribution solves.
Caching user-specific content at a shared CDN edge without per-user cache keys
Wrong
Better
What you see: One user briefly sees another user's personalized data — a severe privacy/security bug — because the CDN cached a response keyed only on a URL that was identical across requests from different logged-in users.
Why: A CDN caches by whatever key it is told to use, most commonly the URL — if a personalized response is cacheable by URL alone with no per-user distinction, the CDN cannot tell it apart from a request that legitimately wants the same cached response for everyone, and will serve one user's cached response to the next.
- Client — e.g. Tokyo
- leads to CDN edge (request)
- CDN edge — nearby PoP
- leads to Hit: ~5ms (cached)
- leads to Origin (miss: fetch + cache)
- Hit: ~5ms — served from edge
- Origin — us-east, single region
What typically is and isn't a good CDN caching candidate
Remember: A CDN caches content at edge locations near users, cutting both network latency and origin load — for static assets by default, and for dynamic content when it is explicitly marked cacheable and does not vary per user.
See also: cache control and invalidation · cacheable vs private content

