Loading...
Loading...
Content delivery network for global distribution
Visualize how a Content Delivery Network reduces latency by caching static assets geographically closer to users.
Green = Edge Hit (20ms) • Amber = Origin Fetch (210ms)
You already know from the caching module how time-to-live expiry bounds staleness, and from the DNS module how a name lookup can answer with different addresses by location. Same page, two users: one near your main server loads it in 40ms, one across an ocean waits half a second. Same code, same database, the only difference is thousands of miles of fiber plus the routers in between. Physics does not negotiate, so the industry stopped asking it to: keep copies near users instead. A CDN (content delivery network, a fleet of cache servers spread across cities that serve copies on behalf of your origin, meaning your main server) does exactly that.
Think of neighborhood library branches, the one comparison we will use here: instead of mailing every book from one central warehouse, popular titles sit on shelves near readers and only rare requests travel the full distance. In the lab above, fetch the same image with the network off and on and watch the far reader drop from hundreds of milliseconds to tens, because the second fetch never leaves the neighborhood.
The naive setup serves everyone from the origin. We rejected keeping it once traffic leaves one region because that layout is simple and always fresh, yet it charges every distant user the full round trip while the origin absorbs every spike. Nearby copies trade a little freshness work for a large latency and cost win.
10 to 20 times faster for repeat content: 250ms divided by 15ms is about 16 times. At 95% served from the branch, 1,000 requests cost the origin only 50 full fetches instead of 1,000.
Every fetch walks the same path: find the nearest branch, check its shelf, fetch from the origin only on a miss, then serve nearby. The vocabulary is small. DNS (the directory that turns names into addresses) answers with the nearby branch address. A cache HIT means the branch had it. A cache MISS means it must phone home once.
A PoP (point of presence, a small data center full of cache servers) sits in or near a major city. Large networks run hundreds of them, so most users sit within tens of milliseconds of one. The edge case is the first viewer after a purge in a far city: they pay the full origin trip so everyone after them does not have to.
Cache-Control is the expiry note attached to each reply, telling branches how long a copy stays valid. Immutable files (content whose address changes whenever the bytes change, like versioned images) can live for a year. HTML and API replies get minutes plus a recheck. Personal data bypasses the branch entirely.
Images, fonts, and bundles with a hash in the name. A new build means a new name, so old copies can never be wrong.
Cache briefly but recheck with the origin after expiry, a behavior called must-revalidate. In the lab, set 300 seconds and edit the origin at second 60 to watch 240 seconds of stale reads.
Account pages and baskets bypass the branch, because serving your receipt to a neighbor is a breach, not a speedup.
A viral video is absorbed by hundreds of branches instead of one origin. The origin sees one fetch per branch per expiry window, not one per viewer.
At 90% branch hits, origin traffic falls to a tenth. The arithmetic is direct: 10 terabytes of viewing becomes 1 terabyte from the origin plus cheaper branch delivery.
A flood aimed at one address spreads across the fleet. A WAF (web application firewall, a filter that blocks malicious requests) and traffic scrubbing at the branch drop junk before it reaches you.
TLS termination (decrypting the secure connection) happens at the branch, so the long-haul leg can reuse efficient connections instead of redoing handshakes per user.
Large general networks, services running branches in hundreds of cities for any website, carry a large share of web traffic and bundle attack protection with caching, because the same branch that serves fast can also filter first.
Video specialists place cache boxes inside internet providers themselves. At hit rates above 90%, almost every play starts locally, which is the only way evening peaks stay affordable: 95 hits per 100 plays means 20 times fewer origin trips.
Over half the internet arrives via branch copies, not origins. But copies raise the oldest question in caching: what happens when the original changes. When your own price or headline updates, how long may a stranger's branch keep serving the old bytes before your purge reaches it?
Try this in the playground
Open a template and build it yourself — then take a quiz.