What are Content Delivery Networks (CDNs)?
Tags: webdev, beginners, cloud, architecture
Published: 2024-05-25 08:23:54

Imagine running an application that serve latest news in the form of 100-words articles. News in the form of such short articles allowed your application’s users to consume lot more news in a short time.

With growing popularity of your application, the load on your application server started growing exponentially. Initially you increased your server’s capability to serve more requests, but you soon realised that this was not sustainable. You dig deep to find a better solution for this problem. You found the following usage pattern for your application ~
* Users that were geographically closer to each other almost consumed the same set of news articles
* While the number of users were large at any point in time, the news articles that they consumed in-together wasn’t that large. In other words, people read almost the same set of articles during a given interval.

All this made you to think of caching news articles. However, this cache needs to be different for different geographical locations. You researched further and found a perfect solution called Content Delivery Networks (CDNs).

This is how Cloudflare defines CDN ~
> **_A content delivery network (CDN) is a geographically distributed group of servers that caches content close to end users. A CDN allows for the quick transfer of assets needed for loading Internet content, including HTML pages, JavaScript files, stylesheets, images, and videos._**

So how does CDN works? There are the following three crucial components to it.

➙ **_Origin Server_**: This is the application server that contains the source of truth. Any updates are made to the contents of the origin server.

➙ **_Edge Servers_**: These servers are located in multiple geographical locations that are called “**_Points-of-Presence_**” or “**_PoP_**”. Content from the origin server is cached here and is served to the clients. In case of missing data, origin server is used to respond to the client’s query and for simultaneously updating edge server’s cache.

➙ **_DNS Servers_**: Domain Name Systems (DNS) servers keep track of the origin and edge server. On a DNS lookup, IPs of both the origin and the edge server.

While caching is one of the biggest advantages of CDNs, it is not the only one. There are several other advantages like decreased server loads, improved site performance, and protection against cyber-attacks. All these benefits are the reason why most of the internet today is being served up by CDNs.

### Types of CDNs

Based on how the cache in edge servers is updated, two types of CDNs exists: **_push_** and **_pull_**.

**Push CDNs** push contents from origin server to the edge servers. Updated content is pushed periodically which is then served up by the CDNs. The cache data from edge server is not removed until the data is explicitly deleted or overridden by the updated data.

**Pull CDNs** is the complete opposite of push CDNs. Here, the edge servers are responsible for pulling in data from the origin server. The process works like this: as the website owner, you maintain the content on the origin server and adjust the URLs to point to the CDN. Subsequently, when a request is made for a web page, the CDN fetches the necessary elements and files from the origin server and presents them to the visitor.

### Popular CDNs
Almost always you would use services of a CDN provider instead of setting up your own CDN. There are some very good options out there, some of them being ~
* _Akamai_
* _Cloudfront_
* _Azure CDN_
* _Cloudflare_

---

With this we reach the end of this blog. Give yourself a pat on the back if you make it this far!