System Design
Content Delivery Networks

Content Delivery Networks

Imagine you're in New York and you want to access a website whose main server is in California. It will take some time for your request to travel all the way to California and then come back with the website you want to see. This is where a Content Delivery Network, or CDN, comes in handy. A CDN makes sure that the website you want to visit is copied and stored at a closer location, let's say in New York itself. So, the next time you want to visit that website, you get it almost instantly.

Definition

Content Delivery Network (CDN) is a system that delivers web content or resources to users based on their geographical location. CDNs are primarily used to serve static resources like images, CSS, JavaScript files, and sometimes even entire web pages, to distribute the load, save bandwidth, and speed up access for end-users.

How Does It Work?

The Main Components

  1. Edge Servers: Think of these like mini-stores that are closer to your home, as opposed to a big warehouse far away. These are servers that are closer to you and store a copy of the website you want to access.

  2. Origin Server: This is the 'main store' or the original location where the website's content is actually stored.

  3. DNS Resolver: It's like a GPS for the internet. When you ask for a website, it tells your computer where the closest mini-store (edge server) is.

  4. Cache: This is like the storage room of each mini-store (edge server), where copies of the website are kept for a short time.

The Process

  1. You want to watch a video or see a picture online.

  2. Your computer asks the DNS Resolver, “Hey, where can I find this?”

  3. The DNS Resolver points your computer to the nearest edge server.

  4. This edge server checks its storage room (cache) to see if it has what you're looking for.

    • If yes, it shows you the video or picture quickly.
    • If no, it will get it from the main store (Origin Server) and then show it to you.
  5. You get to see the content much faster than if it had to come from far away.

Why Is It Useful?

  1. It's Fast: No one likes waiting, and CDNs make sure you get what you want quickly.

  2. Always Available: Even if one mini-store is closed, another will be open. So you always get what you're looking for.

  3. Saves Data: Because it uses smart ways to show you content, it uses less data, which is good for everyone.

  4. Handles Traffic: Imagine everyone wanting to shop at the same time; CDNs make sure the store doesn’t get too crowded.

  5. Security: They have good security to make sure that the data is safe and protected.

Where Do We See CDNs?

  1. Netflix and YouTube: Ever wondered why videos load so fast? CDNs!

  2. Online Shopping: Pictures of products load quickly so you can shop without waiting.

  3. News Websites: They use CDNs to make sure that the latest news reaches you quickly.

  4. Downloads: When you're downloading a new app or game, CDNs make sure it's speedy.

So the next time you’re streaming your favorite show or shopping online, remember that a CDN is working behind the scenes to make your experience smooth and enjoyable.