Guide to Content Delivery Network

23 Jan 2022 ⏱️ 5 min
Guide to Content Delivery Network

Remember the last time when you were reading blogs like this, watching videos or scrolling through shopping sites. Each time you were using CDN indirectly. CDN is one of the backbone of modern world internet infrastructure and solves an important problem of latency. Static assets like images and videos are now almost on every website, larger the files -> higher is the bandwidth required to serve these assets. CDN solves this exact problem by distributing assets on servers throughout the network.

This article is a part of System design series. In this article, I’ll explain about CDN and how it works. We will also cover the benefits of CDN and when to avoid CDNs. Also, this is a common component of system design interviews that you don’t want to skip. Let’s learn CDNs.

Preparing for Interviews? I highly recommend Mastering System Design course on Educative.


Introduction to CDN

In simple terms, A content delivery network (CDN) is a network of group of servers that are geographically distributed. These group of servers work together to provide faster delivery of assets. As the name suggests, CDN ensures faster transfer of assets needed for the Internet including images, videos, HTML pages, etc. At core, CDNs responsibility is to ensure the content is delivered throughout the globe efficiently. Over half of all traffic is already being served by CDNs. That’s how important is CDN to internet.

CDN Overview

For example - I own the next social media website that is serving customers throughout the world. But since I’m serving this website from some server in India, a visitor accessing from US would face higher load times and bandwidth due to large distance.

To avoid the confusion, a CDN doesn’t host content rather it helps in caching content at the network edge. With the help of global network of servers, CDN virtually shortens the physical distance between customer and origin servers, resulting in better site load times and performance.

Today, a lot of cloud services provide CDN. Some of the popular ones are Cloudflare CDN, AWS Cloudfront, GCP Cloud CDN and Azure CDN. Do check them out if you want to use CDN in your websites.


How does CDN works?

CDN is a network of servers linked together with the goal of delivering content as quickly, cheaply, reliably, and securely as possible. In order to improve speed and connectivity, a CDN will place servers at the exchange points between different networks.

CDN uses Internet exchange points aka IXP that help in exchanging data between ISPs across network. By having a connection to these high speed and highly interconnected locations, a CDN provider is able to reduce costs and transit times in high speed data delivery.

To minimize the distance between the visitors and your website’s server, a CDN stores a cached version of its content in multiple geographical locations. Each location (IXPs) contains a number of caching servers responsible for content delivery to visitors within its proximity.


Types of CDN

There are two types of CDN that are used based on how data is transferred between CDN and origin server.

Push based CDN

In this type, the website owners need to push new data to CDN. CDN then propogates the new data across it’s network of servers. Push CDNs require more maintainance effort since you have to push new changes to CDN.

Push based CDN

Pull based CDN

In this type, CDN checks if a file is present. If not, then it fetches the asset from origin server, cache the new data and then send it to user. One problem in Pull based CDN is invalidated cache. If CDN already has a cache, it won’t fetch file from origin server even if it has a newer version of that file. But, this can be solved with invalidating cache after a certain threshold of time.

Pull based CDN


Benefits of CDN

  • CDN helps in distributing data closer to the customers that helps in reducing website load times. Without CDN the client request needs to be served by the origin server. Thus CDN can reduce bounce rates and increase the amount of time that people spend on the site.
  • CDN can handle more traffic and withstand hardware failure better than many origin servers. If if one of the server of CDN goes down, the distributed network ensures that the request is served efficiently. Thus, CDN ensuring high availablilty for services.
  • Since it lies on the edge of the network, CDN helps in improving security by mitigating against DDOS and other security vulnerabilities on your applications.
  • CDN can store reduced file size version using file compression that can help in improving load times. This results in serving different file sizes based on bandwidth.

When to not use a CDN

if you are running a strictly localized website or your customers lie in a specific geographical location. Then, serving them by hosting server in that region should a fair choice. There is no need to use CDN and add additional network hop for no benefit. Conversely this can rather impact your website performance. Also CDN is not the best choice when your data is quite dynamic because the cache needs to be updated quickly.


Resources

Do explore articles on Golang and System Design. You’ll learn something new 💡

I hope you learned something new. Feel free to suggest improvements ✅

I share regular updates and resources on Twitter. Let’s connect!

Keep exploring 🔎 Keep learning 🚀

Liked the content? Do support :)

Paypal - Mohit Khare
Buy me a coffee