Concept 7 · Scaling and Trade-offs·21 min read
Content Delivery Networks (CDNs)
Why moving the bytes closer works wonders for content everyone shares, and almost nothing for content nobody shares.
Big Idea
A CDN keeps copies of your content sitting near the people who ask for it, so distance stops being the thing that decides how fast your site feels. Whether that pays off at all comes down to how many people one copy can answer: enormously, when the bytes are identical for everybody, and close to nothing when every request deserves a different reply.
Why This Exists
One Server Cannot Be Near Everybody
A single origin server, however powerful, is physically far from most of its users, and the speed of light itself puts a floor on how fast a round trip to a distant server can be. No amount of server tuning shortens the distance.
A popular video or a viral image generates an enormous number of near-identical requests for the exact same bytes, and serving every one of them from one origin spends bandwidth and compute on work the origin already did once.
A single point of origin is also a single point of failure and a single bottleneck under load. A launch, a live event, or an attack aimed at that one server can take down every user's experience at once.
Think Of It Like
One Press, Or A Shop In Every Town
Picture a single printing press serving an entire country. For a poster everybody wants, that is an absurd arrangement: each reader mails in an order, the press runs off one more identical sheet, and the post carries it back across the country. Send the master to a print shop in every town instead and the whole problem dissolves, because one plate can serve a queue of any length and nobody is waiting on the mail.
Now make it a certificate with the reader’s own name on it. No local shop can print what it has never seen and could not have guessed, so every order travels back to the one press that holds the records. The shops are still there, still close by, still cheap to run, and for this job they contribute nothing except one more counter to queue at on the way.
The Shape Of It
Origin Pull: One Miss, Then Hits
The first user in a region pays for everyone who follows
Anatomy
The Six Pieces
The server near the user that answers the request. How many there are, and how close they are, is most of what you are buying.
The one server or cluster that holds the authoritative copy. The edge is a copy of it, never the source of truth.
What an edge node considers 'the same request'. Usually the URL, optionally plus specific headers, and getting it wrong caches one user's response for another.
How long an edge node may serve its copy before re-checking the origin. The dial between freshness and hit ratio.
The fraction of requests answered from the edge rather than forwarded. The single number that tells you how much the CDN is actually doing.
The way content is removed before its TTL expires: an explicit purge, or a new URL. Both work, only one is instant everywhere.
The Concept
How The Edge Actually Works
A CDN is a distributed network of edge servers, also called points of presence, or PoPsPoint of presence. One of a CDN’s physical locations: a rack of caching servers in a data centre or inside an ISP’s network, holding copies of content for the users around it. A provider’s PoP count and placement is most of what makes one CDN faster than another in a given country., spread across many geographic regions. Each one holds cached copies of content close to the users in that region, so a request is served from a nearby node instead of crossing an ocean to the origin.
You never pick a PoP, and the URL never changes. Two mechanisms do it for you: DNS that answers with a different address depending on where the question came from, and anycast, where many PoPs announce the same IP and the network delivers to whichever is closest. It is why the same link loads from a machine in Lisbon for one reader and one in Lima for another.
The CDN does not have the content until the first request for it arrives at an edge node. That first request is forwarded to the origin, the response is cached at the edge, and every subsequent request in that region is served from the cache until it expires. No upfront setup, but the first user in each region pays full origin latency.
The origin proactively uploads content to edge nodes ahead of any request, so every user gets a cached response from the very first request. This suits content you know in advance will be popular everywhere, like a scheduled major release, at the cost of pushing data to regions that may never ask for it.
Images, CSS, JavaScript bundles, fonts and downloadable files are the CDN's ideal workload: the exact same bytes are correct for every single user, so one cached copy serves unlimited requests until the content itself changes, giving a near-perfect cache hit ratio.
Video files are large, popular ones are requested repeatedly by huge numbers of viewers, and CDNs split video into small chunks so a player requests just the next few seconds from the nearest edge. That also lets quality adapt mid-stream without re-fetching the whole file.
An account dashboard, a search result unique to one query, an authenticated API call: the response depends on who is asking and what they asked, so there is effectively nothing shared to cache. Most such requests still reach the origin, meaning the CDN adds a network hop without adding a cache hit.
A long TTL means a stale asset, an outdated CSS file after a deploy, can keep being served for a while. This is why deployed static assets are given content-hashed filenames: a changed file becomes a genuinely new URL, so it can never collide with a stale cached entry.
Because edge nodes absorb the vast majority of repeat requests, only a small fraction of real traffic ever reaches the origin. That both reduces origin load during normal spikes and blunts many denial-of-service patterns, since the flood is spread across a global network rather than aimed at one machine.
Some CDNs run small pieces of application logic on the edge node itself: A/B test routing, header rewriting, redirects, cheap authorization checks. It is genuinely useful for per-request work that would be silly to send to the origin, but it is a narrow slice of logic, not a replacement for real personalized backend processing.
Key Terms
The Vocabulary Of The Edge
A CDN server located geographically close to end users, holding cached copies of content so requests do not need to travel all the way to the origin.
A caching mode where content is fetched from the origin and cached at the edge only after the first real request for it arrives, requiring no upfront upload.
A caching mode where content is proactively uploaded to edge nodes ahead of demand, guaranteeing fast responses from the very first request in every region.
The fraction of requests an edge node serves directly from its cache rather than forwarding to the origin, the key metric for how much load a CDN is absorbing.
A filename that includes a hash of the file's contents, so any change produces a new filename and therefore a new cache entry, avoiding stale-cache problems after a deploy.
Small pieces of application logic executed directly on a CDN's edge nodes rather than at the origin, used for lightweight per-request work like routing or header rewriting.
The routing trick that makes one IP address resolve to whichever PoP is nearest the user. It is how a single URL reaches a different machine depending on where you ask from.
An edge node that does not yet hold a requested object, so the request becomes a miss and pays the full trip to the origin. Every region starts cold under origin pull.
Worked Example
Origin Pull vs Origin Push
The Shape Of It
The Floor Under Every Round Trip
Round-trip latency against distance, before your server does any work at all
Light in fiber travels at roughly two thirds of its speed in a vacuum, which works out to about one millisecond of round trip per hundred kilometres. A user in Sydney talking to a server in Virginia is around 16,000 km away, so physics alone charges them about 160 ms before a single byte of application work happens, and real routing, which never follows a straight line, pushes that past 200 ms in practice.
Nothing you do to the server moves that number. A faster database, a bigger instance, a tighter query, all of it is optimising the small slice of the bar that is not distance. Putting a copy of the response 50 km from the user is the only change that moves the dominant term, and that is the entire argument for a CDN.
Counterpoint
What Benefits, And What Does Not
Static assets: images, CSS, JavaScript bundles, fonts
Video and audio streaming, chunked and cached per segment
Content identical for every viewer, like a public landing page
Large downloads where bandwidth cost, not just latency, is the problem
Personalized dashboards and account pages, unique per user
Search results and query-specific API responses
Anything requiring fresh, per-request authentication or state
Writes, which have to reach the origin by definition
One honest exception to the right-hand column: on a large CDN a forwarded request is not simply an extra hop. The edge terminates TLS next to the user, so the handshake’s several round trips are short ones, and it reaches the origin over already-open connections on the provider’s own backbone rather than whatever path the public internet picks that day. Sold as dynamic site acceleration, it is a real but modest win, and it is worth knowing the shape of it: you are shortening the path for uncacheable traffic, not removing it.
Reference
How Each Kind Of Content Caches
| Content | Cache Key | Workable TTL | How It Changes | Why |
|---|---|---|---|---|
| Versioned JS/CSS bundle | URL alone | A year, immutable | New hash, new URL | The ideal case: the URL changes whenever the bytes do |
| Product image | URL alone | Days to weeks | Purge, or a version in the path | Rarely changes, read constantly, identical for everyone |
| Video segment | URL alone | Effectively forever | Never; segments are immutable | Chunked so a viewer only pulls the seconds they watch |
| Public landing page | URL, maybe locale | Minutes | Purge on publish | Same for everyone, but has to reflect edits quickly |
| Logged-in dashboard | Would need the user | Not cached | N/A | No two responses are alike; the edge is pure overhead |
| Search results | Would need the query | Seconds, if at all | N/A | The long tail of queries is never requested twice |
Failure Mode
The Stale Asset After A Deploy
You ship a new version. The HTML is fresh, the server is fine, the logs are clean, and some fraction of your users see a broken, half-styled page. Their browser is loading new markup against a styles.css that an edge node fetched an hour ago and is contractually entitled to keep serving for another twenty-three.
A purge API fixes it after the fact, and every CDN has one, but it is a repair, not a design. The design is to never reuse a URL for different bytes: build output named app.4f9c2b.js changes its name whenever its contents change, so the old entry is simply never requested again and the new one has nothing stale to collide with.
That leaves exactly one file that must not be cached hard: the HTML that names the hashed assets. Give it a short TTL or revalidate it every time, cache everything it points at for a year, and the stale-asset problem stops existing rather than being managed.
Counterpoint
A Shield, Not A Capacity Plan
A CDN is a genuine first line of defence. Repeat requests die at the edge, so a spike that would have flattened one machine is instead spread across a global network, and a large share of crude denial-of-service traffic never reaches the origin at all. Sites routinely report that the overwhelming majority of their requests never touch their own servers.
The trap is reading that number as headroom. The share the edge absorbs is the cacheable share, and the uncacheable remainder, logins, checkouts, searches, writes, grows with the spike just as fast as everything else. Ten times the traffic is also ten times the logins. The CDN divides origin load by a constant; it does not change what happens when the input goes up.
Seen In The Wild
Edges You Use Every Day
Cloudflare and Akamai run global CDN networks serving a large share of the web's static assets, images and even API traffic for millions of sites, absorbing traffic that would otherwise all hit individual origin servers. Akamai alone reports more than 4,100 edge locations across 120 or so countries, which is the scale the word 'nearby' is doing work at.
Netflix built its own purpose-built CDN, Open Connect, placing caching appliances directly inside ISP networks so video travels the shortest possible path to viewers, a scale problem generic CDNs were not built to solve as cheaply.
YouTube relies on Google's global edge infrastructure to cache and serve video chunks close to viewers worldwide, letting a video uploaded once be watched by millions without every view routing back to one data center.
Amazon CloudFront and Fastly cache static assets and accelerate some dynamic traffic for e-commerce and media sites, cutting page load time by answering from an edge location near the shopper.
Key Points
What To Carry Forward
A CDN reduces latency and origin load by caching content at edge nodes physically close to users.
Origin pull caches lazily on first request; origin push uploads ahead of demand for a guaranteed fast first request.
Static assets and video benefit enormously because the same bytes are correct for every viewer, giving near-perfect hit ratios.
Personalized or dynamic content barely benefits, since a response unique to one user has nothing to share with the next request.
TTL and invalidation still matter at the edge, and content-hashed filenames are the standard fix for stale assets after a deploy.
CDNs absorb traffic spikes and blunt some attack traffic simply by serving repeat requests before they reach the origin.
Every edge node caches independently, so there is no single moment when a deploy becomes visible everywhere.
Edge compute handles cheap per-request logic at the PoP, but it is not a place to move your backend.
Common Mistakes
Where This Usually Goes Wrong
Assuming a CDN speeds up everything, then being surprised when a personalized API endpoint sees no improvement after being put behind one.
Setting a long TTL on assets without content-hashed filenames, so users keep getting a stale, broken version of a file after a deploy until the TTL finally expires.
Treating origin pull and origin push as interchangeable, when push is only worth its upfront cost for content you are confident will actually be requested broadly.
Forgetting that the first request in each region under origin pull still pays full origin latency, and expecting a brand-new asset to be instantly fast everywhere.
Relying on a CDN instead of origin capacity planning, when a spike in genuinely dynamic, uncacheable traffic still arrives at the origin at full force.
Caching a response that varied on a header or a cookie without putting that in the cache key, which serves one user's content to the next user who asks.
“The lamppost on the corner is my edge node. Every dog in this postcode writes to it, so I get the whole day’s news in four seconds without walking the block, and I have never once needed to meet any of them. What is not on the lamppost is which of my two humans is holding the bowl tonight. Nobody posts that. For that one I make the full trip home, every evening, and I am never told in advance.”
Try It Yourself
Find The Edge In A Site You Already Use
Further Reading
Where To Go Deeper
A free, local-first coach for DSA, mock interviews and system design. Zero nudges you toward the answer instead of handing it over, and nothing leaves your machine.
The reference explainer from a company that runs one: performance, reliability, security and bandwidth cost, and why a CDN is not the same thing as web hosting.
The same question answered by the oldest CDN operator: origin, edge and DNS as three cooperating roles, plus what accelerating uncacheable dynamic content actually means.
What it looks like when the CDN is the product: appliances placed inside ISP networks, because a generic edge was not close enough or cheap enough at that scale.
Quiz Review
Check your understanding
Question 1 of 5
Why does a CDN help almost nothing for a personalized dashboard endpoint, even if the endpoint is popular?
- ✓Caching only helps when many requests can be served the same cached response. A personalized dashboard returns different data for every user, and often different data on every request, so there is no shared content for the edge node to have cached from a previous request. Nearly every request still has to be forwarded to the origin, and the CDN adds a hop with no cache hit to show for it.