Programming
We provide developers and engineers the guides and tutorials they...
Search
We provide developers and engineers the guides and tutorials they...
Content is king. It's not just about how you're going to write, b...
Looking for an engaging connection with thousands of other people...
How a content delivery network works: edge servers, anycast routing, caching with Cache-Control, cache hits and misses, and when you need a CDN.
Quick answer: A content delivery network (CDN) is a network of servers spread across many cities. Each edge server keeps copies (a cache) of a website's files. When you request a page, you're routed to the nearest edge. If it has a fresh copy, it answers immediately. If not, it fetches the file once from the site's main origin server, returns it to you, and keeps a copy for the next visitor nearby.
Cloudflare's Learning Center sums it up as a geographically distributed group of servers that cache content close to users.
Data can't travel faster than light, and in fibre it moves at roughly two-thirds of light speed. A request from London to a server in Sydney covers about 17,000 km each way, so every round trip costs at least around 170 ms before any work is done.
That matters more than it sounds, because loading a page takes many round trips. DNS, the TCP handshake, the TLS handshake, then the request itself, and then more requests for CSS, scripts and images. Multiply 170 ms by all of those and a distant server feels sluggish no matter how fast it is.
There's a second problem: load. If every visitor in the world hits one origin, a traffic spike or an attack can take it down. A CDN absorbs most requests before they ever reach the origin.

A CDN has three moving parts: routing users to a nearby edge, caching content there, and fetching from the origin when the cache can't help.
When you look up www.example.com, the site's DNS usually points to the CDN rather than the origin. CDNs then steer you to a nearby point of presence (PoP) in one of two ways:
Either way, the DNS lookup is where the CDN first takes over.
The edge checks whether it has a fresh copy of the requested URL. If yes, that's a cache hit: it replies straight away, often within a few milliseconds of you. The origin never hears about the request.
If the edge has no copy, or its copy has expired, that's a cache miss. The edge fetches the file from the origin, sends it to you, and stores it. The next visitor in that region gets a hit.
Many CDNs add a middle layer called tiered caching or an origin shield: edges ask a regional cache first, so a popular file is fetched from the origin once per region instead of once per edge.
The key health metric is the cache hit ratio: the share of requests answered from cache. A high ratio means fast pages and a quiet origin.
A CDN can only be as smart as the instructions you give it. The main lever is the Cache-Control response header, covered in depth by MDN's HTTP caching guide.
| Header | Meaning | Good for |
|---|---|---|
Cache-Control: public, max-age=31536000, immutable | Anyone may cache it for a year and it will never change | Versioned assets like app.3f9a1c.js |
Cache-Control: public, max-age=300 | Cache for 5 minutes | Home pages, listings, news |
Cache-Control: s-maxage=600, max-age=0 | CDNs cache 10 minutes; browsers always revalidate | HTML you want to update quickly |
Cache-Control: private, no-store | Never cache in shared caches | Account pages, anything personalised |
Three more concepts matter in practice:
style.8d2e1f.css). Then you can cache them forever, and a new deploy simply references new URLs.The classic mistake is caching something personal. If a response contains one user's data and lacks private, a CDN can serve it to the next visitor. Treat caching headers on logged-in pages as security settings, not just performance ones.
Modern CDNs are less "file cache" and more "programmable front door" for a site:
You probably want one if:
You might skip it for an internal tool used from one office, or an API whose responses are all personalised and uncacheable. Even then, a CDN's security and TLS features can still be worth it.
Where CDNs fit in the bigger picture: they sit in step 5 of what happens when you type a URL, between the browser and everything else.
No. Hosting stores the original site and runs its code. A CDN sits in front and caches and delivers copies. You still need an origin.
Often, for short periods. A news home page can be cached for 30 seconds and still feel live. Truly personal pages (like a shopping basket) shouldn't be cached in shared caches, though edge compute can assemble them close to the user.
The old version is still cached, either at the CDN or in your browser. Purge the URL at the CDN, and use versioned file names so new deploys never collide with old caches.
Indirectly. Faster pages improve user experience and Core Web Vitals, which search engines consider. A CDN also keeps your site up during traffic spikes, which matters when crawlers visit.
A point of presence: a CDN data centre in a particular city. Large CDNs run hundreds of them.
A CDN beats the speed of light by cheating: instead of making the trip shorter, it moves the content closer. Routing sends each visitor to a nearby edge, caching lets that edge answer most requests itself, and the origin only handles what's genuinely new. Get your Cache-Control headers right and a CDN makes your site faster, cheaper to run and much harder to knock over.