What is a CDN? Explained with local pickup counters
A CDN is a network of servers in many places that keep copies of a website's files, so visitors are served from nearby. Explained with local pickup counters in every neighbourhood.
- Author
Umair Mateen- Published
- Reading time
- 5 min
- Category
- DevOps
In one sentence: A CDN (content delivery network) is a group of servers spread across many places that keep copies of a website's files, so each visitor is served from a nearby copy instead of from one faraway main server.
The everyday picture
Picture a shop with one big central warehouse. Every order is packed there and sent out. Customers close by get their parcels quickly. Customers in another country wait much longer, and on a busy day the warehouse gets swamped.
Now the shop opens small pickup counters in neighbourhoods all over the world. Each counter keeps the most popular items on its shelf. You walk to the counter nearest you and collect your item in minutes. Only when the counter does not have something does it order from the central warehouse.
That is a CDN. The central warehouse is your website's main server, called the origin. The pickup counters are the CDN's edge servers. The shelf at each counter is its cache: a store of ready copies.
The visitor is served by a nearby edge server (the counter). If the copy is on its shelf, it is handed over at once. If not, the counter orders it from the origin server (the warehouse) and keeps a copy for next time.
How it works, step by step
- A visitor asks for a page or file (a shopper wants an item). Behind the scenes, the address lookup (DNS) points them to an edge server that can answer quickly, usually the nearest one (the counter down the road).
- The edge server checks its cache (the counter checks its shelf). If a fresh copy is there, it hands it over straight away. This is called a cache hit.
- If the copy is missing or out of date (the shelf is empty or the item is past its date), the edge server asks the origin server for it. This is a cache miss. Some CDNs, such as Amazon CloudFront, also have larger regional caches in between, like a regional depot.
- The origin sends the file back (the warehouse ships the item). The edge server passes it to the visitor and keeps a copy on its shelf for the next person nearby.
- Copies are kept for a set time (a use-by date on the shelf). When it runs out, the counter fetches a fresh one. The website owner can also tell the CDN to clear a copy early, for example after updating a price list.
Try it · Myth or fact
CDNs: myth or fact?
Decide for yourself first, then tap each statement to check it.
0 of 4 checked
Where the picture stops
- A real counter hands over the item and no longer has it. An edge server hands over a copy, so one file can serve thousands of visitors at once.
- Not everything sits on the shelf. Personal pages, like your account or basket, and actions like sending a form usually go through to the origin, because they are different for every visitor.
- A CDN does not replace your hosting. Cloudflare's own guide says a CDN does not host content. You still need the origin server; the CDN sits in front of it.
Why it matters for your business
- Speed for visitors far away. Pages, images and videos load faster because they travel a shorter distance. Faster pages are easier to use, wherever your customers are.
- Lower load and cost at the origin. Most requests stop at the counters, so your main server handles fewer of them. Cloudflare notes that every response from the origin uses bandwidth, which can add to hosting costs.
- Staying up on busy days. A launch or a sale can bring a rush of visitors. Spreading them across many edge servers helps your site cope, and if one location fails, traffic can be sent to another.
- Some protection from attacks. A properly set-up CDN can help absorb some common attacks, such as floods of fake traffic (DDoS), before they reach your server.
An example
Imagine a small furniture maker in Portugal that sells online to customers in Europe and North America. Its website runs on one server in Lisbon. Shoppers in Canada complain that the product photos load slowly.
The team puts a CDN in front of the site. Now the photos, styles and scripts are copied to edge servers in many regions. A shopper in Toronto gets the photos from a nearby counter. The checkout and customer accounts still go to the Lisbon server, because they are personal. When the team uploads new photos, they clear the old copies so everyone sees the new ones.
Frequently asked questions
Do I need a CDN for a small website?
Not always. If most of your visitors are near your server, the gain is smaller. Many hosting platforms already include a CDN, so you may have one without knowing it.
Is a CDN the same as web hosting?
No. Hosting is where your website lives (the warehouse). A CDN keeps copies of its files closer to visitors (the counters). It works alongside your hosting, not instead of it.
Why do I still see an old version of my site after an update?
An edge server may still hold the old copy until it expires. Most CDNs let you clear (purge) copies so the new version is fetched from your server.
What is the difference between a CDN and caching?
Caching means keeping ready copies to save work. A CDN is one place that caching happens: a network of servers in many locations that keep those copies near your visitors.
Related explainers
- What is caching? Explained with a restaurant kitchen
- What is a server? Explained with a kitchen that never closes
- What is DNS? Explained with your phone's contacts list
- What is cloud hosting? Explained with a serviced office
The DevDrift sets up hosting, CDNs and monitoring for web platforms: see how.
Sources
Could you explain this to a colleague now?
Mark it and posts that mention it will show a tick. Saved in this browser only.