How do companies like Netflix deliver content around the world ?
Tags: beginners, cloud, webdev, programming
Published: 2022-12-11 23:43:30

---
title: How do companies like Netflix deliver content around the world ?
published: true
description: A primer into Content Delivery Networks (CDNs)
tags: beginners,cloud,webdev,programming
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2022-12-11 23:25 +0000
---

## Content 

- [Introduction](#introduction)
- [How It Works](#how-it-works)
- [Types of Assets](#type-of-assets)
- [Use Cases](#use-cases)
  - [Performance](#peformance)
  - [Security](#security)
  - [Personalization](#personalization)
- [Conclusion](#conclusion)

## Introduction

Content Delivery Networks (CDNs) are technologies that helps to efficiently distribute and deliver data around the world. 

Many popular website and applications (**ie Netflix, Spotify, Reddit, Twitter etc** 🤠) are most likely using a CDN.

Maybe you’ve developed an application that is content rich like a blog or a news site for a global audience — then there is a high likelihood that the site is using a CDN!

**So, how does a CDN work ? 🤔**

Before we talk about that, let’s first understand how a request works without a CDN.

In an infrastructure without a CDN, the request needs to go through multiple network hops to get to the server (ie data center) and then back to the client (the user). 

**Depending on the distance (between the client and the server), this can have drastic impact on the performance.**

![Image Direct access to origin server](https://www.jerrychang.ca/images/cdn-intro-direct-access-to-origin.png)

So, what is the limiting factor here ?

**It’s the physical distance between the server and the client**

This is because speed of light can travel only **299, 792, 458 meters per second (m/s)**.


![Image Speed of light](https://www.jerrychang.ca/images/cdn-intro-speed-of-light.png)


That means we are limited in how fast the data can be transferred.

The only other option is to reduce the physical distance between the client and server — That’s exactly what you can achieve when you use a CDN.

By introducing a CDN, we can strategically place servers that sit closer to the user, and these servers are referred to as “edge locations”.

This allows us to minimize the phyiscal distance between the data centers (ie servers) and the users (ie clients).

What you end up with is a network infrastructure that is optimized for global data distribution, and delivery!

![Image Accessing the data through the edge locations](https://www.jerrychang.ca/images/cdn-intro-access-to-edge-locations.png)

**In the subsequent sections we’ll go through the following:**

- How it works
- The type of assets
- Use cases 

It may seem like the data magically appears at these edge locations but that is not the case.

There is a process that happens in order to make this possible, let’s go through that in more detail.

## How it works

So, when you first introduce a CDN into your infrastructure, here is what happens.

The initial request is no different than any other request, it will still reach out to the origin server to retrieve the assets (ie html, js, images).

After the retrieval, these assets from the initial request can now be cached at these edge locations (if the CDN is configured to do so).

![Image First request to the origin server](https://www.jerrychang.ca/images/cdn-intro-first-request.png)

It is through this process that these assets become available at these edge locations. 

Then, in the subsequent request, here is where the magic happens.

It can now reach out to the edge location first to retrieve the asset (cached version) before going to the origin server.

![Image Subsequent request to the origin server](https://www.jerrychang.ca/images/cdn-intro-subsequent-request.png)

Then when the cache expires, meaning the content is now stale, it will go through this whole process again.

## Type of assets

Any type of assets that is served through the origin server can be accelerated and delivered through the CDN.

**The assets include:**

- HTML pages
- JS files
- CSS files
- Images
- Videos
- Files (PDF, Documents etc)
- and other assets

## Use cases

So, when would you leverage a CDN ?

As we already discussed, the typical application for CDNs are for content acceleration and delivery of static content to the global audience around the world.

However, CDNs are not just limited to this application.

There are many interesting ways you customize your infrastructure through the use of a CDN.

Let’s go through each of them.

**Here are some areas that CDNs can be applied to:**

- **Performance**

- **Security**

- **Personalization**

### Peformance

By leveraging these edge locations, the content delivery can be accelerated for the global audience.

The content is moved from the origin servers to these edge locations which results in a reduction in the response times (latency).

From an end user perspective, this means a better user experience (UX) while browsing the application. 

### Security

Using a CDN is not going to automatically improve security but it does provide capabilities that you can leverage to harden security.

Most of the time, the operators are responsible for adding the security features but some CDN services do provide out-of-the-box security capabilities (CAPTCHA, DDoS etc) that you can opt into (ie Cloudflare, Fastly, Akamai).

When you have a CDN, it acts like a gateway, the request will go through the CDN before it reaches the origin server. Which means, it can be used to manage of control the incoming and outgoing traffic.

**Some of the applications may include:**

- Access management and control 
- DDoS prevention
- Bot detection 
- TLS management
- Managing security headers
- and much more...

### Personalization 

Another use case for using a CDN is the ability to personalize the content delivery based on the location.

**Here are some examples:**

- Providing an unique offering to a particular region (**By Region**)

- A/B Testing or Feature Roll out by region (**By Region**)

- Optimizing content and experience for a particular device (**By a viewer device**)

- Alter content based on a particular region (**By region**)

- and the list goes on...

## Conclusion

Before we part, let’s do a quick recap!

**Takeways:**

- CDN is a technology that improves performance of the content delivery by moving servers closer to the user


- The keys benefits of CDNs is the performance you get in the content delivery & distribution (Reducing the time it takes for content to reach the user, Latency)


- Beyond performance, other applications of CDNs include security and personalization 

That’s it!

If you found this helpful or learned something new, please share this article with a friend or co-worker 🙏❤️ (Thanks!)