DEV Community

Swapnil Shelke
Swapnil Shelke

Posted on

CDN's: What are they and how they work and why do we need them?

CDN stands for Content Delivery Network.

This thing is used, when we create objects in object store, that files will obviously exists somewhere in world. So when we upload files to AWS or any cloud provider that file exists somewhere in world. Somewhere in any server for ex: server in USA.

Now suppose, suddenly lot of people wants to access this file, from all over the world.

Now how this will work is, all requests from all this people, from all over the world, will go to that single server in USA through very long wires and bunch of router hopes. The request will reach to the server and responses will be send back. This is very big file, for ex, 1 GB.

Wouldn't it be nice, if lot of people asking this file from India, what if this request goes to server which is somewhere present in India first, and everyone in India and then from this server, users who asked for file gets their response.

That is what CDN's let us do. It's name itself tells that its job is to deliver content.

CDN says, there are many object stores in world, let that be the source of your truth, but as people ask for any particular file, don't distribute it directly from S3 URL, use my CDN URL and just tell me what's the source is.

So whenever we create CDN we just have to tell it what is the source, where that file is actually stored. So whenever anyone asks for a file to CDN it goes to source, later CDN cached that file on to the server present in India. So whenever anyone wants that file from India, it gets deliver to them easily. Now every request will not go to server in USA, because we have cached it, somewhere on server present in India.

Request from users in India goes to server present in somewhere [closest] present in India, which then asks source of truth, the place / server where it is originally stored, gets it back to server in India, and then caches it. So now that file not only present in server in USA but also in India. And now whoever wants it, they get it from server in India.

Objects / files / data is not cached for infinity, they are cached for certain period of time and after that time is over, the cache gets clear.

The main thing here to understand is how CDN's actually works. Content Delivery Networks make it very easy to deliver content. The thing that is so hard and expensive, if some file present only at one place in the world, and people / users from all continents starts to ask for it, CDN's creates what we called servers but they are technically are called as POP's. POP's stands for Point of Presence.

Object stores, store or files at one place, CDN's have servers all over the world, which are technically called as POP's.
This is very useful in case of very heavy applications, who not just store bunch of data, this are serving actual real world assets. Like mp4, jpeg files.

So we not just need object store, we also need CDN's. Object stores are use for storage and CDN's are use for Distribution. And we have to pay for both of services if we are using AWS. And usually distribution cost is higher.

cdn

Top comments (0)