loading...
Cover image for What is CDN and how do they work.

What is CDN and how do they work.

akhilpokle profile image Akhil ・3 min read

CDN is short for Content Delivery Network. It's a geographically distributed group of servers that work together to provide fast delivery of internet content.

Content: The content or assets can be anything, HTML pages, CSS files, Javascript files, images, videos, songs etc.
So when we type this line :

<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">

we're basically asking google fonts to provide us with the particular font design.

Delivery: Self-explanatory.

Network: Why is it called network?
It's called a network since bunch for servers work together to send "content" back to the client.

If you've played any of multiplayer online games like Dota or CS:GO, there's a command which we type: "ping" and it returns something like "100ms" or "40ms".

Alt Text
dota 2 ping for different regions

Ping is how much time it takes for the server to return the content asked by the client. So 100ms means that it takes 100ms for client -> server -> client data transfer. So in this case, if I am connected to a USEast server, then the data exchange between me and the server on which the actual game is running takes 26ms.

But why a cluster of servers?

Now imagine you're in US, and you want to play with your friend in India so you decide to join a server in India. So for data transfer between you and the server now takes 300ms on average, which doesn't seem much but for a high paced game like Dota, it's too much or as gamers call it "LAG".

Here's an example of the same in Fortnite:

In this case if player 1 ping = 300ms and player 2 ping = 26ms, the actions performed by player 2 are received, processed, and distributed much faster compared to player 1.

The same applies to all other services like Netflix, Spotify etc. It would be unfeasible to store all movies and TV shows, at one location.
To tackle this, they install a bunch/cluster of servers in many different locations that contain data, and these in turn are connected to the main server which provides all the data.

Alt Text

Implementing this kind of network has many advantages:

1> Decreased load : Each server will serve customers in that region which brings down server load of whole system.

2> Faster Content Delivery : Since load is decreased, it's easier on server transfer files.

3> Protection against potential DDOS attacks : Since there are many servers located, if one server is affected by DDOS attack, other backup servers will kick into action and serve customers in that region, and overloading the main server becomes difficult.

4> Analytics : Companies like Netflix use the data about things like, most-watched movies / TV shows in that region and use that data to update their regional servers so that relevant content is available to customers.

Eg: if customers in US are watching "Stranger Things" at high demand and customers in South Korea are watching "Kingdom", Netflix will update their local US and Korean servers accordingly.

Netflix, in particular, goes beyond. Netflix ties up with local ISP to install boxes similar to these :
Alt Text

Since the population density of Mumbai is higher compared to that of New York, Netflix might end up installing more of these boxes in Mumbai to serve their customers.

Comment down below if I missed something or messed somewhere.

Thanks for reading :)

Sources :
https://www.youtube.com/watch?v=YXQpgAAeLM4
https://hackernoon.com/powering-your-app-with-a-realtime-messaging-cdn-13d92a6df5f3
https://www.cloudflare.com/learning/cdn/what-is-a-cdn/
https://medium.com/refraction-tech-everything/how-netflix-works-the-hugely-simplified-complex-stuff-that-happens-every-time-you-hit-play-3a40c9be254b?source=search_post---------0

Posted on by:

akhilpokle profile

Akhil

@akhilpokle

Hi, I am Akhil. I write about Tech, How tech works, and algorithmic problems. I write so I remember what I learned.

Discussion

markdown guide
 

Bruhh! Don't want to read? Watch the text converted video -.. :) youtu.be/G4owjm4wKJs

 
 

I like how you wrote this article.
Regarding CDN, I've always wondered if it's really worth it for a lot of sites that are using it.
If you don't have heavy resources (videos. large-resolution images, etc), I don't think a user would notice that the site loaded 2 milliseconds faster.

 

True that, infact Netflix is handling all it's video content via CDN, and the rest of the stuff like handling billings, user logins, recommendation system etc is using AWS and Google cloud.