# CDN

> Copies of a website kept on servers around the world, close to whoever asks.

- Level: Intermediate
- Topics: Networks, Cloud
- URL: https://tidbit.legios.com.ar/cdn/
- In Spanish: [CDN](https://tidbit.legios.com.ar/es/cdn/)

A **CDN** (content delivery network) is a set of servers spread across many cities that keep copies of a website's files: images, videos, scripts, whole pages. When you open the site, your request goes to the nearest of those **edge** servers instead of travelling to the company's own server, the **origin**, which may be on another continent. Shorter distance means lower latency, and the page appears faster.

The edge works as a **cache**. If it already has the file you asked for, that is a **cache hit** and it answers on the spot. If not, a **cache miss**, it fetches the file from the origin once, keeps a copy, and serves it to everyone nearby who asks next. The site decides how long each copy may live: a logo can stay for a month, a news front page maybe for a minute.

Almost every big site uses one. A video service in Buenos Aires does not stream every episode from Virginia; it streams from a server a few kilometers away. The origin also gets far fewer requests, so it needs less capacity, and because a CDN has huge total bandwidth spread across the world, it can absorb traffic floods like a DDoS attack that would knock a single server over. Amazon CloudFront, Cloudflare, Akamai and Fastly are well-known CDNs.

## An analogy

A bakery chain. The recipe and the main kitchen (the origin) are in one place, but every neighborhood has a branch with fresh bread on the shelf (the edge), so you walk two blocks instead of crossing the city.

## Keep in mind

- Edge servers near users keep copies of files from the origin server.
- A cache hit is answered at the edge; a cache miss goes to the origin once.
- The site controls how long each file may stay cached.
- Besides speed, a CDN shields the origin from load and traffic floods.

## Go deeper

- [What is a CDN? (AWS)](https://aws.amazon.com/what-is/cdn/)
- [CDN (MDN glossary)](https://developer.mozilla.org/en-US/docs/Glossary/CDN)
- [Content delivery network on Wikipedia](https://en.wikipedia.org/wiki/Content_delivery_network)

## Related terms

- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
- [Bandwidth and latency](https://tidbit.legios.com.ar/bandwidth-and-latency/): How much data fits per second, and how long each trip takes. Two different things.
- [DDoS](https://tidbit.legios.com.ar/ddos/): Knocking a site offline by flooding it with more traffic than it can handle.
- [Amazon CloudFront](https://tidbit.legios.com.ar/amazon-cloudfront/): AWS's CDN: copies of your content kept close to users all over the world.
- [Cloudflare](https://tidbit.legios.com.ar/cloudflare/): A global network that sits in front of websites to make them faster and safer.
