Content Delivery Networks (CDN)

[!NOTE] This module explores the core principles of Content Delivery Networks (CDN), deriving solutions from first principles and hardware constraints to build world-class, production-ready expertise.

1. What is a CDN?

A Content Delivery Network (CDN) is a geographically distributed group of servers which work together to provide fast delivery of Internet content. If your server is in New York and your user is in Tokyo, a CDN caches your content in Tokyo so the user doesn’t have to wait for the data to travel around the world.

2. Key Terminology

  • Origin Server: The primary source of your data (e.g., your AWS S3 bucket or your Web Server).
  • Edge Location / PoP (Point of Presence): The CDN servers located strategically around the globe near end-users.
  • Latency: The time it takes for a request to travel to the server and back. CDNs reduce this by shortening the physical distance.

3. How it Works

  1. Request: User in London requests image.jpg from your site.
  2. DNS Routing: The CDN’s Anycast DNS routes the request to the London Edge Location.
  3. Cache Hit: If the image is in the London cache, it is served immediately. (Fast!).
  4. Cache Miss: If not, the Edge server fetches it from the Origin, stores it for future users, and serves it to the current user. (Slower the first time).

4. Interactive: The Latency Map

See the difference between Origin and Edge.

📱
User (India)
Edge (Mumbai)
Origin (Virginia)
Choose a route.

5. What content can be cached?

  • Static: Images (JPEG, PNG), CSS, JavaScript, Video (MP4). (Great for CDNs).
  • Dynamic: Personalized HTML, API responses. (Harder to cache, but CDNs can help with connection optimization).
  • Security: WAF (Web Application Firewall) and DDoS protection often sit at the CDN Edge to block attacks before they even reach your servers.