Sunday 5 May 2024

What is CDN (Content Delivery network) and How it works?

CDN stands for Content Delivery Network, acts as a service to enhance the speed of content delivery in applications, making websites respond faster. To illustrate, consider a scenario where you've developed a learning website with users scattered across the globe, yet your application isn't deployed worldwide.

 

Suppose you've developed a learning website with a user base spanning the globe. However, your application is deployed only in New Delhi Datacenter.

 

Here are the approximate distances between New Delhi and the cities where your application users reside:

 

1.   Colombo: Approximately 2,000 kilometers (1,240 miles).

2.   Beijing: Approximately 3,600 kilometers (2,200 miles).

3.   Moscow: Approximately 4,000 kilometers (2,500 miles).

4.   Madrid: Approximately 7,100 kilometers (4,400 miles).

5.   Cape Town: Approximately 7,500 kilometers (4,660 miles).

6.   London: Approximately 7,600 kilometers (4,700 miles).

7.   Sydney: Approximately 10,300 kilometers (6,400 miles).

8.   New York: Approximately 11,800 kilometers (7,300 miles).

 

 


Let's examine the user journey for those in Colombo. When they make a request to the website, the data must travel 2,000 kilometers to New Delhi and back, totalling 4,000 kilometers. Generally, response times are measured in milliseconds. For instance, let's assume a round trip time of approximately 200 milliseconds for a 2,000-kilometer distance:

 

Colombo: Approximately 2,000 kilometers (1,240 miles) : 200 milliseconds

 

Now, considering the distances to other cities:

 

1.   Beijing: Approximately 3,600 kilometers

Network call time = (200 milliseconds * 3,600) / 2,000 = 360 milliseconds

2.   Moscow: Approximately 4,000 kilometers

Network call time = (200 milliseconds * 4,000) / 2,000 = 400 milliseconds

3.   Madrid: Approximately 7,100 kilometers

Network call time = (200 milliseconds * 7,100) / 2,000 = 710 milliseconds

4.   Cape Town: Approximately 7,500 kilometers

Network call time = (200 milliseconds * 7,500) / 2,000 = 750 milliseconds

5.   London: Approximately 7,600 kilometers

Network call time = (200 milliseconds * 7,600) / 2,000 = 760 milliseconds

6.   Sydney: Approximately 10,300 kilometers

Network call time = (200 milliseconds * 10,300) / 2,000 = 1,030 milliseconds

7.   New York: Approximately 11,800 kilometers

Network call time = (200 milliseconds * 11,800) / 2,000 = 1,180 milliseconds

 

These computations assume a linear correlation between distance and time, which may not fully reflect real-world scenarios due to other factors such as network infrastructure and latency. In summary, the greater the distance, the longer it takes to deliver data to users, resulting in slower website performance.

 



How CDN helps in this scenario?

CDNs tackle this challenge by minimizing the distance between users and content. Typically, CDNs establish content delivery network endpoints in as many locations worldwide as possible. Here's an overview of some leading Content Delivery Networks (CDNs) and the regions where they commonly maintain a presence:

 

1.   Akamai: Akamai operates one of the largest CDNs globally. Its reach spans major cities in North America, Europe, Asia-Pacific, and South America.

2.   Cloudflare: Covering over 200 cities worldwide, Cloudflare boasts a widespread network of data centers. Its presence extends across North America, Europe, Asia-Pacific, Africa, and South America.

3.   Amazon CloudFront: Amazon CloudFront's vast network of edge locations is dispersed across multiple continents, including North America, South America, Europe, Asia-Pacific, and the Middle East.

4.   Google Cloud CDN: Leveraging Google's expansive global infrastructure, Google Cloud CDN maintains edge locations in numerous cities across North America, Europe, Asia-Pacific, and other regions.

5.   Microsoft Azure CDN: With edge locations in various cities across continents, including North America, Europe, Asia-Pacific, and the Middle East, Microsoft Azure CDN has a comprehensive global presence.

6.   Fastly: Operating a network of edge servers in major cities worldwide, Fastly has a robust presence in North America, Europe, Asia-Pacific, and South America.

7.   KeyCDN: KeyCDN's global network of POPs (Points of Presence) spans major cities across North America, Europe, Asia-Pacific, and other regions.

 

To simplify this example, let's assume that the CDN we're utilizing is available in all the locations where our users are located.

 


 

Now, when a user in Beijing attempts to access the content, it's initially fetched by the Content Delivery Network Service and then distributed globally to all the nodes in CDN. Consequently, users in London no longer need to access the application deployed in New Delhi to retrieve the content; they can directly access it from the nearest CDN. This significantly reduces the time taken to deliver the content. Additionally, CDNs reduce the amount of traffic reaching the server deployed in New Delhi.

 

Points to consider while choosing a CDN

a. Cost: The pricing structure of a CDN can vary significantly depending on factors such as data transfer volume, request rates, and additional services. It's essential to evaluate the cost-effectiveness of different CDN providers based on your traffic patterns and budget constraints.

 

b. Cache Expiry Policies: CDN cache expiry policies determine how long content remains cached at edge locations before it's refreshed from the origin server. Understanding and configuring cache expiry policies appropriately can impact content freshness and performance. Consider whether the CDN offers flexible options for setting cache expiry times based on content type or URL patterns.

 

c. CDN Fallback Implementation (When CDN is Down): It's crucial to have a fallback strategy in place for situations when the CDN experiences downtime or performance issues. This may involve configuring DNS failover to direct traffic back to the origin server or utilizing alternative CDN providers as backups.

 

d. Invalidating CDN Content via APIs: CDNs typically offer APIs or control panels to programmatically invalidate cached content when updates are made to the origin server. Evaluate the ease of use and effectiveness of these invalidation mechanisms, as efficient cache invalidation is essential for timely content updates.

 

e. Availability of CDN Across the Globe: Consider the geographical coverage of the CDN provider's network to ensure adequate reach for your global user base. Assess the number and distribution of edge locations worldwide, as well as the network's performance in regions where your users are concentrated.

 

f. Security Features: Evaluate the CDN's security offerings, including DDoS protection, SSL/TLS encryption, and access control mechanisms. Robust security features are essential for safeguarding content and mitigating potential threats.

 

g. Analytics and Reporting: Consider the availability of analytics tools and reporting features provided by the CDN for monitoring traffic, performance metrics, and usage patterns. Insights from these analytics can help optimize content delivery and troubleshoot issues effectively.

 

h. Scalability and Traffic Handling: Assess the CDN's scalability capabilities to accommodate traffic spikes and growing user demand. Look for features like auto-scaling and load balancing to ensure smooth performance under varying traffic conditions.

 

By carefully considering these factors and conducting thorough evaluations, you can choose a CDN that best aligns with your requirements for cost-effectiveness, performance, reliability, and scalability.


                                                  System Design Questions

No comments:

Post a Comment