# Content Delivery Network

## Summary


A Content Delivery Network (CDN) is a collection of servers located around the world that work together to deliver content to users faster by bringing it closer to them. CDNs store a copy of content in Cache Servers or Edge servers in point-of-presence (POP) locations close to end users to reduce loading time and overloading on a single origin server. 

Although a CDN does not replace the need for web hosting, it does help with content caching at the network edge, which improves website performance in ways that traditional web hosting services struggle. 

CDNs can cache various form of contents like web pages, image, video also live streaming without storing the entire recordings caching it as segments.

## Discussion

### Why do we need a CDN?

A CDN is useful for websites or web applications that have a high volume of traffic and a large number of users from all over the world. Due to the higher latency in the network during transmission, visitors from all over the world will experience longer loading times because websites are hosted on a single server in a single location. By reducing page loading times, a CDN improves the user experience. 

The primary goal of a content delivery network (CDN) is to reduce latency, or the delay that occurs in a website's response to a user request. CDNs help to reduce latency by distributing content across multiple servers maintained by CDN providers around the world, rather than a single server to handle website traffic. .

CDNs can not only provide customers with faster loading speeds, but they can also prevent website crashes in the event of a spike in traffic. . More than 41% of the top 10,000 websites use a CDN to deliver their content, according to BuiltWith, a technology lookup tool.  


### How do CDNs work?

A Content Delivery Network (CDN) is a network of servers that distributes content from a "origin" server where the content is originally hosted via proxy servers that receive client requests and forward them to other edge servers located around the world. 

Edge servers in a CDN can be either data centres with multiple servers or Points of Presence (PoP) with a single server. These are strategically placed across multiple geographical locations, where the content is cached before being served via CDN. 

Caching refers to the practise of storing copies of data pulled from an origin server on edge servers. It helps the origin server in reducing traffic stress on a website by bringing edge servers closer to the users, which reduces loading time as less travel time is required to reach the user. 

CDN Edge servers are usually located near Internet exchange points (IXPs), which connect various internet service providers to exchange traffic. . CDN providers can save money and time by locating servers in these interconnected locations.   .

Equal-cost multipath (ECMP) is one of the routing strategy that edge servers use to balance traffic and efficiently use bandwidth. 


### What are the benefits of using a CDN?

 

    + **Improving site Reliability**: Even during common network issues such as hardware failures or network traffic congestion, CDNs can keep website content online. Usage of CDNs can avoid traffic congestion by using load balancing to distribute traffic equally across multiple servers. Some CDN providers use the anycast routing method to efficiently handle traffic and routing it to the nearest data centre with high traffic handling capabilities to avoid congestion.
    + **Increased Security**: The use of CDNs can help to prevent various cyber attacks such as common DDoS ,in which an attacker floods a website with abnormally high traffic, overloading server and making it unresponsive .While these attacks are becoming common, Cloudflare a CDN provider, has prevented a DDoS attack with a peak of 17.2 million requests per second (rps), which is three times higher than previous records proving the security of CDN.
    + **Scalabilty**:Because a CDN distributes the contents across many servers around the world, the website owner does not need to change the demands of the webserver based on traffic needs because the CDN handles it and scales it accordingly.

### What is Push and Pull caching in CDN?

When we talk of global CDN network, it refers to caching content at various edge server locations such that the data is available to any requesting global user. It can actually be classified into two types push and pull based on how it caches the data from the origin server. 

Push CDN distributes a website's content at regular intervals from the origin server to edge servers (PoPs) located all over the world. Visitors to the website are served from an edge server copy of the website. It works in the same way as prefetch  . Push CDN is ideal for low-traffic websites and files that are mostly static and do not change frequently. 

Pull CDN, also known as Reverse Proxy, does not store the contents of a website on CDN Edge Servers until the user requests that resource for the first time. .When a user requests content from the Edge server, it contacts the origin server and obtains a copy to deliver to the user. All future requests for that content will be served from the Edge server's cache. It is best suited for smaller files such as images, javascript, and so on. 


### Could you explain some terminologies used in CDN?

 

    + **Cache Hit**: A "cache hit" occurs when a user requests files from the Edge server's cache and the Edge server is able to successfully deliver them from the cache rather than the origin server.
    + **Cache Miss**: This happens when the requested file by the user is not found in the Edge server and the request is passsed onto "Origin Server" to deliver it to the user. Once the origin server responds, the CDN server caches, so that subsequent requests for it results in a cache hit.
    + **Cache hit ratio**: A count of the number of content requests that are successfully fulfilled by Edge servers. It is calculated by *Number of cache hits/(Number of cache hits + Number of cache misses) = Cache hit ratio*.
    + **Purge**: The edge server's cached version of a file is removed, and the origin server begins delivering the newer version of the content to the edge server.
    + **Prefetch**: It is used to provide a faster delivery experience to the user. To avoid cache misses, content that is likely to be requested by a large number of users is cached on Edge Servers.

### Which should you use Multi-CDN or Single CDN?

In the Multi-CDN model, Traffic is distributed across multiple CDN providers, such as Cloudflare, Akamai, and AWS, Multi-CDN enables the combination of capacity from multiple providers and provides fault tolerance in the event of a failure.  .

Different CDN providers will have individual Edge Servers with different infrastructure and unique features, resulting in different performance, security, and usage costs. Multi-CDN can be set up with the help of third-party providers such as NS1. They serve as CDN brokers, aggregating several CDN providers.  

In single CDN model, the users use only one CDN provider for their website, and is recommended for businesses that want to distribute their content only to specific geographic locations and do not have a global audience. It also reduces multiple DNS lookups, as opposed to Multi-CDN, which uses three DNS lookups, slowing down the initial connection to the CDN. 


### What is Request collapsing in CDN?

Request collapsing, also known as collapse forwarding, is a key feature of CDN architecture that prevents Edge servers from being overloaded by a large number of simultaneous requests to access content from the CDN while it is being cached to edge servers or is yet to be cached in the CDN, resulting in a cache miss. 

The problem is known as *Thundering Herd* or *Cache Stampede*. Many large companies in the tech industry experienced outages as a result of it.  . Request collapsing helps to solve this problem by combining multiple requests for the same content into a single request.

If there is cache miss for the requested content and a second request for the same content arrives in the meantime, the second request is queued. After the file is sent from the origin server to the CDN Edge servers, it is finally delivered to everyone who requested it. 

Some CDN providers take this concept a step further by incorporating "origin shield" between Edge servers and origin servers in the CDN by incorporating caching layers to reduce the number of requests made to the origin server for content. 


### How does CDN cache dynamic content?

Content on a website will be either static or dynamic. Static content will be same for every user which needs almost no processing by a backend in server specifically for the user. It is easy to serve by a CDN as the information once cached in the server will not change. Traditional CDNs have cached and served only static content but CDNs now a days need to process dynamic content in which the data changes depending on user, location and many other factors.

Caching dynamic content via CDN is complex because it requires querying a database, using Full Page Caching or reverse proxy caching also executing large code base to generate the content. It was once impossible to cache dynamic content, but with the advancement of modern CDN technologies, it is now possible to do so by running the code and storing databases closer to the users on Edge Servers and delivering it from the cache rather than pulling it from the distant origin server, which even speeds up the response time of dynamic websites to the user. 


### Difference between CDN and Edge Computing

While CDN aims to improve user connectivity by caching content copies in edge servers. Edge Computing is a similar architecture aimed primarily at IoT (Internet of Things) sensors, Gateways, Smartphones, and a wide range of technologies not limited to high performance servers. 

It can not only store content like a CDN, but it can also distribute workload and provide decentralised computing, processing services for applications such as VR, AR Gaming, and others that require high reliability and ultra low latency with the help of growing 5G technology. It can replace a CDN Edge Server which performs the majority of the computing services on the origin server and stores the copies, whereas in Edge Computing, the majority of what happens in CDN origin servers happens closer to the user. 

Beacause the required infrastructure for a Edge computing varies greatly than a CDN. Users of edge computing services for their business require a tailor made solutions according to their specific requirements. 


### What are the Disadvantages of using a CDN?

    + **Expensive**: Starting to use a CDN and setting it up takes time and comes with a lot of hidden costs. There are many CDNs that offer free plans, but they come with some restrictions. Because it can handle large amounts of traffic, the fees are determined by the number of visitors, the amount of CDN resources used, and a variety of other factors. As a result, CDN networks are typically a better option for large businesses with the financial resources and requirements to invest in them.
    + **Server Location**: Before you set up, learn about CDN providers and their points of presence (PoPs). If you don't have a CDN provider's server near where your core audience and majority of traffic is expected, it will have a negative impact on your website's performance as it will directly increase the loading time for the users.
    + **Handling SEO**: Though using a CDN improves page speed, which is beneficial to SEO, there are a number of other factors that if handled incorrectly can have a negative impact on SEO. It is recommended that assets such as images be hosted on the same sub-domains as the website.


## Milestones

1995

Tim Berners-lee inventor of World Wide Web realised internet traffic congestion would become a major problem limiting internet usage. They start a research project in MIT to find a solution. 

Aug  
1998

Dr. Leighton and Mr. Lewin incorporated Akamai meaning "clever" or "intelligent" in Hawaiian language. It is the first CDN provider and the company is evolved from a MIT Project in 1995. 

Feb  
1999

Akamai provides first live traffic to Disney website via CDN. It starts earning a considerable market share by delivering two programmes for ESPN and Entertainment tonight, which historically had a high consumer demand. Also in the same year world's most visited website Yahoo is their customer. 

Aug  
2000

Dr.Tom leighton MIT math professor and his student Daniel Lewin got patent for their intelligent routing system which replicates content across a large network of distributed servers. It is titled as "Global hosting system".


Sep  
2001

The 9/11 terrorist attack in United States increases internet usage worldwide. During this MSNBC a news Channel consumes a bandwidth of 120 gigabits per second, compared to the normal 6 gigabits.  After this event more money is invested in the development of advanced CDNs to handle such flash crowds. Daniel Lewin, the father of CDN and founder of Akamai CDN, is coincidentally killed in this terrorist attack.  

Nov  
2007

A new architecture distributed Content Delivery Network (DCDN) is proposed in the IEEE research paper to improve the peering of CDN which allows traffic to be exchanged between two networks directly increasing the efficiency of Commercial CDNs. Resources of the internet users like storage space and bandwidth is used in DCDN. 

Nov  
2008

Amazon Web Services(AWS) subsidiary of Amazon.com,Inc launches CloudFront a content delivery network with 14 edge locations around the world. A Huge advantage of Cloudfront is the pay as you go pricing model with no upfront cost or long term contract.  

Nov  
2009

Microsoft launches Windows Azure Content Delivery Network. The data is delivered by blob containers which can store large unstructured data served to users by over HTTP or HTTPS protocols. Public Blob containers are available for anyone for anonymous access with the CDN URL. Data Request is served from the closest CDN endpoint of the user to access the Blob. Azure CDN uses cache in which a very-high speed memory to deliver static objects allowing users to store large amount of data. 

Apr  
2010

Limelight Inc's patent application is published. In which a new system for delivering encrypted data to end-users from a Content Delivery Network origin is proposed. Some or most of the contents within the CDN is encrypted and when the end-user supplies a Universal Resource Indicators (URI) the CDN determines the key for decrypting the content before it is delivered to the end-user from CDN.


Jun  
2012

Netflix a subscription based streaming service launches "Open Connect Network" , CDN to serve petabytes of data on a In-house content distribution network to provide billion hours per month of movies and TV which was served by other commerical CDN providers previously. Netflix provides free servers to the Internet Service Providers which stores copies of Netflix contents to reduce the burden on networks by eliminating the number of transits for the content to reach the user in the network. 

Sep  
2017

Edgemesh a web acceleration company has started to operate 3,500 Global networks through Peer-to-Peer Content delivery network technology which cuts the page loading time by 60% reducing bandwidth fees by 90%.  

Jun  
2018

A New PCDN Technology introduced by Alibaba Cloud is emerging to offer Peer to Peer functionality optionally integrated with a CDN. This PCDN depends on Peer to Peer technology which can be integrated with conventional CDN and Cloud-based CDN. The Cost of PCDN is also cheaper than traditional and Cloud-based CDN. Multi-level node scheduling increases data redundancy which means the data can be served by both CDN and P2P technology. 

Jul  
2019

For about 30 minutes, many websites on the internet displayed a 502 error due to a major outage in Cloudflare CDN. It's because of a bug that caused a massive spike in CPU usage, which caused the system to crash.  

2020

Due to the COVID pandemic, CDN usage is on the rise, with Video on Demand (VOD) and Over the Top (OTT) services playing a major role. With 15.8 million new users, Netflix, an OTT platform, saw a 48 percent increase in traffic. Similarly, edtech platforms have seen an increase in usage.