Understanding Content Delivery Networks (CDNs)

Introduction

As we have learned about caching in previous articles, we already know what caching is. Caching is about storing frequently used data for faster retrieval.

Consider the example of a librarian: Instead of going to the bookshelf every time to get a book, the librarian keeps the most popular books nearby. This way, they don’t have to make repeated trips, which would be time-consuming. By doing this, the librarian can provide books much faster, reducing delay. This is what caching is, as we explored in previous articles.

Similarly, just like caching data, we also cache content.

What is a Content Delivery Network (CDN)?

What is CDN (Content Delivery Network)? - ClouDNS Blog

Let’s take an example. Imagine you are watching a YouTube video—let’s say a video by MrBeast. Normally, this video is stored on a server in the United States.

When you request to watch the video, YouTube retrieves it from the USA and sends it back to you. However, this process can take a lot of time since the distance between the server and you is significant.

Now, what if we apply the same caching ideology and store the video closer to you?

Instead of requesting the video from the USA every time, a server in India could store a copy of that video. The first time someone requests it, the server in India fetches the video from the USA, stores it, and delivers it to the user.

Now, when someone else in India requests the same video, they don’t need to fetch it from the USA. Instead, they can get it directly from the local server, reducing delay.

How Does a CDN Work?

A CDN is a way to deliver content efficiently across the world by caching it at multiple locations. These are servers located near you that store the content of the original server, helping to reduce latency (the time it takes for data to travel).

However, you might now wonder:

What if the server in India gets overloaded because the video is trending and millions of people are watching it?

That’s where multiple servers come into play. Instead of a single server, there are many servers in a region. This collection of servers is called a Point of Presence (POP).

Each individual server within a POP is known as an Edge Server.

How Does Your Device Know Which Server to Contact?

Since there are multiple edge servers, how does your phone know which one to request content from?

There are two primary methods:

1. DNS-Based Routing

  • DNS stands for Domain Name System—it stores the IP addresses of websites so that users don’t have to remember them.

  • Using this method, each edge server has a unique IP address.

  • When you request content, the DNS provides the IP address of the nearest edge server, ensuring fast delivery.

2. Anycast Routing

  • In Anycast, every edge server has the same IP address.

  • When you request content, Anycast automatically finds the nearest edge server and routes your request to it.

  • This ensures that you receive data as quickly as possible.

Beyond Caching: Other Benefits of CDNs

CDNs are not just about caching—they offer additional advantages as well.

1. Load Balancing

We’ve discussed load balancing in previous articles. Here’s how CDNs help:

  • Instead of requesting data from the main server, you request it from a local edge server.

  • This prevents the main server from getting overloaded.

  • The CDNs (edge servers) act as load balancers, distributing the load efficiently.

2. Security Enhancement

CDNs also provide security benefits:

  • Instead of your request going directly to the main server, it first goes through an edge server.

  • Edge servers can perform security checks, preventing malicious attacks.

One major threat CDNs help prevent is a DDoS attack (Denial-of-Service Attack).

  • In a DDoS attack, hackers send a huge number of requests to a server, overwhelming it and making it unavailable.

  • With CDNs, the requests get distributed across multiple edge servers instead of targeting a single main server.

  • Each edge server has security measures in place to detect and block such attacks, improving security.

3. Maintaining HTTP Connection

Another important role of edge servers is to maintain persistent HTTP connections:

  • Connecting to a main server (e.g., in the USA) takes time due to distance.

  • Instead of connecting to the USA server every time, your device only connects to a nearby edge server.

  • The edge server already has an active connection with the main server.

  • This significantly reduces connection time, improving the speed of data delivery.

Conclusion

By establishing a network of CDNs across the world, large companies like YouTube and Netflix ensure that users like you and me can access content quickly, efficiently, and securely.

0
Subscribe to my newsletter

Read articles from Affan Shaikhsurab directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Affan Shaikhsurab
Affan Shaikhsurab