SkillSprout
Chapter 13 · Lesson 1
Beginner
3 min read

What Is a CDN and How Requests Flow

Overview

A CDN is caching taken worldwide: copies of your content sit on servers all around the planet, so users download from a nearby machine instead of your one distant server.

This lesson explains why distance matters, who the players are, and how one request travels.

Detailed Notes

What is a CDN

A CDN (Content Delivery Network) is a network of servers spread across many cities. These are called edge servers (or edge locations, or PoPs - points of presence). Each edge server is a cache. Your own servers, where the real content lives, are called the origin.

The problem it solves

Data travels fast, but not instantly, and distance adds latency. If your origin is in Frankfurt, a user in Sydney waits for many round trips across the world to load a page. A single origin also has to serve every user, so traffic spikes can overwhelm it.

Most of a typical web page is static content: images, CSS, JavaScript, video. Every user gets the same files, which makes them perfect to cache. Dynamic content (a personal dashboard, a bank balance) differs per user and is harder to cache.

A CDN fixes both problems: content is served from nearby (lower latency), and the origin only handles the misses (lower load).

How it works

  1. The user asks for cdn.example.com/logo.png.
  2. DNS (covered earlier) answers with the address of the nearest edge server, not the origin.
  3. The edge server checks its cache.
  4. Hit: it returns the file right away.
  5. Miss: it fetches the file from the origin, returns it, and keeps a copy for the next users nearby.

Because every edge server is a cache, the same ideas from the Caching chapter apply: hit ratio, TTL, stale data. Many CDNs add a middle cache layer (an origin shield) so that many edge misses become just one request to the origin.

A CDN also gives side benefits: it terminates HTTPS close to the user, absorbs floods of traffic (DDoS attacks, where attackers send huge volumes of requests to knock a site over) because the load is spread over hundreds of servers, and shields the origin by hiding it behind the edge.

A simple example

A book publisher in one city used to post every book to every reader. Now they keep stock in warehouses in every region. A reader orders and gets the book from the closest warehouse in a day; the publisher only ships new titles to the warehouses occasionally.

System design example

A video site stores its files in object storage (a service that keeps files such as videos and images, and serves as the origin). Users in India, Brazil and Germany each load thumbnails and video chunks from a local edge server. After the first viewer in a region fetches a file, everyone else nearby gets it from cache. Origin traffic drops by something like 90-99% and page loads speed up for everyone.

Summary

  • A CDN is a worldwide set of cache servers (edges) in front of your origin.
  • It cuts latency by shortening distance and cuts origin load by absorbing hits.
  • DNS directs each user to a nearby edge.
  • A hit is served at the edge; a miss goes to the origin and fills the cache.
  • Static content benefits most; it also helps with HTTPS and attack protection.

Architecture Diagram

A request through a CDN
Architecture
User
Edge Servercache
Origin Servers
Object Storage

The nearest edge answers; only misses reach the origin.

  1. 1DNS sends the user to the closest edge server.
  2. 2The edge returns the file if it has it.
  3. 3On a miss the edge fetches from the origin.
  4. 4It stores a copy for the next users in that region.

Common Interview Questions

Finished this lesson?

0 of 91 lessons done · 0% of the course