What is a CDN and how does it make sites fast worldwide?
A Content Delivery Network keeps copies of your files on servers close to your users, so a visitor in Tokyo doesn't wait for a server in Virginia.
In one sentence
A CDN is a cache spread around the world. Users download images, video, scripts and even pages from the nearest edge server; only the first request in each region goes all the way to your origin.
The problem: distance
Data travels through fibre at about two thirds of the speed of light. A round trip from Sydney to Virginia takes around 200 ms before your server does any work, and loading a page needs many round trips. Faster servers can't fix physics; getting closer can.
How a CDN works
- Your domain points to the CDN (for example
cdn.example.com). DNS sends each user to the nearest edge location. - The edge checks its cache. Hit: it answers in a few milliseconds.
- Miss: the edge fetches the file from your origin (your server or an S3 bucket), stores a copy and answers.
- How long the copy lives is set by your
Cache-Controlheaders (max-age,s-maxage).
Big providers (CloudFront, Cloudflare, Akamai, Fastly) run hundreds of locations. Netflix goes further and places its own servers inside internet providers' networks.
What to put on a CDN
| Content | Fit | Typical setup |
|---|---|---|
| Images, fonts, JS, CSS | Perfect | Hashed file names (app.3f9a.js) + cache for a year |
| Video segments | Perfect | HLS/DASH chunks; most of the traffic of YouTube or Netflix |
| Public HTML pages | Good | Short TTL (seconds to minutes), or stale-while-revalidate |
| API responses that are the same for everyone | Sometimes | Short TTL, cache key without cookies |
| Personal data (cart, inbox) | No | Mark as private or no-store |
Updating files: versioning beats purging
When a file changes you can purge it from every edge (it takes seconds to minutes and is often rate limited), or avoid the problem by versioning: the new file gets a new name (logo.v2.png), so there's nothing to invalidate. Build tools do this automatically with content hashes.
Bonus benefits: the CDN absorbs traffic spikes, hides your origin's IP and usually includes DDoS protection and a web application firewall.
Key takeaways
- 01A CDN caches content on edge servers near users, cutting latency caused by distance.
- 02Only misses reach the origin, so the CDN also absorbs most of the traffic.
- 03Perfect for static files and video; careful with anything personal.
- 04Prefer versioned file names over purging when content changes.
Check your understanding
1 of 3
What does a CDN do?
Related concepts
Caching
A cache stores copies of data that are expensive to get (slow query, far away server) so the next request can be answered from somewhere fast and close.
9 min read →Load balancers
A load balancer is the single entry point that receives every request and forwards it to one of many healthy servers, so no single server is overloaded and failures stay invisible to users.
8 min read →Rate limiting
A rate limiter caps how many requests a client can make in a period ("100 per minute") and answers the rest with 429 Too Many Requests, so one client can't take the system down for everyone.
6 min read →