← All posts

How CDNs Actually Work

Introduction

While using platforms like YouTube, videos load almost instantly regardless of where the user is located. This raised a simple question:

How is content delivered so quickly across the world?

While exploring this, I came across Content Delivery Networks (CDNs).


The problem: Distance and Latency

If a server is located far away from a user:

  • Data takes longer to travel
  • Network latency increases
  • Load on a single server becomes high

For example: If a server is in the US and a user is in India, every request has to travel a long distance.

This results in slower response times.


What a CDN does

A Content Delivery Network (CDN) solves this by distributing content across multiple servers located in different geographical regions.

Instead of: User => Single distant server

It becomes: User => Nearest CDN server

This reduces latency and improves performance.


Key idea: edge servers

CDNs use edge servers, which are:

  • Located closer to users
  • Used to store cached copies of content

When a user requests content:

  • The request is routed to the nearest edge server
  • If the content exists there => it is served immediately
  • If not => it is fetched from the origin server and cached

Example: YouTube video delivery

Consider watching a YouTube video.

Step-by-step flow:

  1. User clicks on a video
  2. Request is routed to a nearby CDN server
  3. Video chunks are served from that server
  4. If not available, CDN fetches from YouTube’s main servers
  5. The content is cached for future users

Important detail:

  • Videos are split into small chunks
  • This allows smooth streaming and adaptive quality

So instead of downloading the entire video, data is streamed piece by piece.


Why CDNs are effective

  • Reduce latency (shorter distance)
  • Reduce load on origin servers
  • Improve scalability
  • Provide faster and more reliable content delivery

They are especially useful for:

  • Videos
  • Images
  • Static assets (CSS, JS)

What I found interesting

  • The idea of storing content closer to users is simple, but implementing it globally is complex
  • Systems like YouTube rely heavily on CDNs for performance
  • Most modern web applications use CDNs, often without developers directly interacting with them

Conclusion

CDNs are a fundamental part of how the modern internet delivers content efficiently. Even without implementing one, understanding the concept helps in appreciating how large-scale systems handle performance and scalability.

What seemed like “instant loading” is actually the result of a well-designed, distributed system working behind the scenes. Crazy system design