What Is a CDN?
A Content Delivery Network (CDN) improves website performance and availability by caching content on distributed servers closer to users, reducing latency and…
In depth
A Content Delivery Network (CDN) is a distributed network of servers that delivers web content to users based on their geographic location. It significantly improves website loading speeds and availability by reducing the physical distance data must travel.
The Latency Problem
Without a CDN, a user's request for website content, such as an image, travels directly to the website's main server, often called the Origin server. If the user is geographically distant from the Origin server, this request and the subsequent response must traverse thousands of miles. This round-trip delay, known as latency, makes websites feel slow and unresponsive.
How CDNs Work
CDNs solve the latency problem by deploying a global network of servers, known as Edge servers, strategically placed closer to users. When a user requests content, the request is directed to the nearest Edge server instead of the distant Origin server.
Anycast Routing
To ensure requests go to the closest Edge server, CDNs often employ Anycast routing. With Anycast, multiple Edge servers around the world share the same IP address. When a user sends a request to this shared IP, internet routers automatically direct the data along the shortest network path, effectively routing the request to the geographically nearest Edge server.
Cache Hits and Misses
Once a request reaches an Edge server, the server checks its local storage for the requested content:
- Cache Hit: If the Edge server already has a copy of the content (e.g., an image), it's a cache hit. The server delivers the content instantly from its local cache.
- Cache Miss: If the Edge server does not have the content, it's a cache miss. The Edge server then fetches the content from the Origin server, saves a copy to its local cache for future requests, and then delivers it to the user.
Time to Live (TTL)
To prevent cached content from becoming outdated, the Origin server assigns a Time to Live (TTL) to each piece of content. This is a countdown timer that tells the Edge server how long it can keep a cached copy before it must discard it and fetch a fresh version from the Origin server.
Key Takeaways
- CDNs reduce latency by serving content from Edge servers geographically closer to users.
- They use Anycast routing to direct user requests to the nearest available Edge server.
- Content is cached on Edge servers, leading to faster delivery on subsequent requests.
- TTL ensures cached content remains fresh and up-to-date.
- CDNs enhance website performance, reduce bandwidth load on Origin servers, and improve overall user experience.
Got a different question? SeaThru generates a fresh video for any topic where systems talk or data structures move.
Ask your own question →