What is a Content Distribution Network and how does it work?
Over the last few years there has been a huge increase in the number of Internet users. YouTube alone has 2 Billion users worldwide, while Netflix has over 160 million users. Streaming content to such a wide demographic of users is no easy task. One can think that a straightforward approach to this can be building a large data center, storing all the content in the servers, and provide it to the users worldwide. But there are issues that arise when this approach is followed-
- Firstly if the data center is in the USA and the user is in India there will be slower delivery of content.
- Secondly, a single data center represents a single point of failure.
- Thirdly, if some content is being accessed frequently from a remote area then it is likely to follow the same links, and this, in turn, results in wastage of bandwidth.
CDN – Content Distribution Network or Content Delivery Network is a solution that provides faster delivery of content to the users distributed worldwide.
What is a CDN?
A CDN is essentially a group of servers that are strategically placed across the globe with the purpose of accelerating the delivery of web content. A CDN-
- Manages servers that are geographically distributed over different locations.
- Stores the web content in its servers.
- Attempts to direct each user to a server that is part of the CDN so as to deliver content quickly.
How does CDN work?
To minimize the distance between the visitors and your website’s server, a CDN stores a cached version of original content in multiple geographical locations (a.k.a., points of presence/ PoPs). Each PoP contains a number of caching servers known as edge servers that are responsible for content delivery to visitors within its proximity. CDN caches content in many places at once, ensuring quick delivery of content.
Let’s consider an example:
Suppose you are hosting a website, wherein your origin server(server containing the primary source of your website’s data, where website files are hosted) is located in Australia and a company XYZ provides you the CDN service.
When a user in India clicks on a video on your website, the request goes to the user’s local DNS server(See DNS), which relays the request to the authoritative DNS server of your website.
The authoritative DNS server then identifies that the user is situated far away and therefore relays the request to its XYZ’s DNS server. Now the DNS query enters XYZ’s network which provides the address of the edge server that is closest to the user to the Local DNS server. The video is delivered by this edge server.
From this point onwards the local DNS server knows the address of the edge server. So whenever users within its network send a request for content from your website, the local DNS server shall relay the request to the edge server.
CDN thus minimizes the number of hops required to deliver the data to a user’s browser due to the POPs that are located near the user.
Following image depicts the same:
Following Image depicts the difference between how a request is handled with and without a CDN respectively:
WITH CDN(2 SECONDS)
WITHOUT CDN(5 SECONDS)