How does a CDN work?

Ankita Panigrahi
2 min readFeb 15, 2022

What is CDN (Content delivery network)?

A content delivery network (CDN) is a group of geographically distributed servers that speed up the delivery of web content by bringing it closer to where users are. (Source: Google)

It is used to deliver static files in a faster way

So basically, when we request a web page from different geographical areas, the request will go to the server. This process will take time to render the page for the user hence increasing the turnaround time. Now CDN comes to picture

How is it done?

  1. Caching
  2. Customized data for different device types or location
  3. Fast

Before the server, we have an entity called cache (write once, update never). For the first time, it will take data from the server and store it in the cache or if there is some invalidation like invalidate every 1 hour. So for 1 hour, we can use the cached version, and then it will get the requests from the server.

One problem with cache is if this crashes, everything crashes. That’s where distributed cache comes into the picture.

Another problem is we are storing a lot of data in the cache. For e.g., we are storing customized HTML pages according to location or language. A person sitting in India will have a lot of irrelevant information from the caching.

This can be solved by sharding which is basically splitting the cache based on the location of the user. So the distributed cache will work in a way like a group of the cache will belong to a particular location and so on. As a result, the number of unique files in the cache grows, the number of requests to the origin decreases, and the speed of content delivery increases.

We have a global distribution system in our cloud which is hosted in a single country, for eg, the USA. A person staying in India requests a page and the requests travel all the way to the USA and come back. For this scenario, we will create a cache in India or southeast Asia, for e.g, China and India can use the same cache. This ensures faster delivery.

If you have a website that is supposed to be used by people across the globe, then you should make use of CDN to minimize turnaround time. Some Popular CDNs are Cloudflare, Cloudfront by Amazon.

--

--