Skip to main content

What is a CDN?

A Content Delivery Network (CDN) refers to geographically distributed servers (also called edge servers) that provide fast delivery of static and dynamic content.
CDNs are distributed server networks that help improve the performance, reliability, and security of content delivery on the internet.
CDN Overview

How CDN Works

How CDN Works Suppose Bob in New York wants to visit an eCommerce website deployed in London. Without a CDN, the request would go to London servers, resulting in slow response times. With a CDN, content is loaded from a nearby CDN server.

CDN Request Flow

Here’s what happens when a user requests content through a CDN:
1

User enters URL

Bob types www.myshop.com in the browser. The browser looks up the domain name in the local DNS cache.
2

DNS Resolution

If not in local cache, the browser queries the DNS resolver (usually at the ISP) to resolve the domain name.
3

Recursive DNS Lookup

The DNS resolver recursively resolves the domain name and asks the authoritative name server.
4

CDN Alias

The authoritative name server returns an alias pointing to www.myshop.cdn.com (the CDN domain) instead of the origin server.
5

CDN Domain Resolution

The DNS resolver asks the authoritative name server to resolve www.myshop.cdn.com.
6

Load Balancer Response

The authoritative name server returns the domain for the CDN load balancer www.myshop.lb.com.
7

Optimal Edge Server Selection

The CDN load balancer chooses an optimal edge server based on:
  • User’s IP address
  • User’s ISP
  • Content requested
  • Server load
8

Edge Server IP Returned

The CDN load balancer returns the optimal edge server’s IP address.
9

Content Delivery

The browser connects to the edge server to load content.

CDN Distribution Network

If the edge CDN server cache doesn’t contain the requested content:
  1. Edge Server (closest to user) - First check
  2. Regional CDN Server - If not found at edge
  3. Central CDN Server - If not found at regional
  4. Origin Server - Final fallback (e.g., London web server)
This hierarchy ensures content is served from the closest available location.

Types of Cached Content

Static Content

  • Static HTML pages
  • Images and graphics
  • Videos and media files
  • CSS stylesheets
  • JavaScript files
  • Fonts

Dynamic Content

  • Edge computing results
  • Personalized content
  • API responses
  • Real-time data
  • Geolocation-based content

Key CDN Concepts

Edge Servers

Edge servers are located closer to end users than traditional servers, which helps:
  • Reduce latency: Shorter physical distance = faster response times
  • Improve performance: Less network hops between user and content
  • Handle traffic spikes: Distribute load across multiple servers
  • Increase availability: Redundancy through geographic distribution

Edge Computing

Edge computing processes data closer to the end user rather than in a centralized data center.
  • Reduced latency for real-time applications
  • Lower bandwidth usage to origin
  • Better user experience
  • Support for compute-intensive tasks at the edge

CDN Benefits

Faster Load Times:
  • Content served from geographically closer servers
  • Reduced network latency
  • Optimized delivery paths
Example: A user in Sydney accessing a US-based website can see load times improve from 2-3 seconds to under 500ms.
High Availability:
  • Multiple redundant servers
  • Automatic failover
  • No single point of failure
DDoS Protection:
  • Distributed architecture absorbs attacks
  • Rate limiting at edge
  • Anomaly detection
Handle Traffic Spikes:
  • Distribute load across many servers
  • Automatic scaling
  • Reduced origin server load
Cost Efficiency:
  • Lower bandwidth costs at origin
  • Reduced infrastructure needs
  • Pay for what you use
Enhanced Security:
  • SSL/TLS termination at edge
  • Web Application Firewall (WAF)
  • Bot mitigation
  • Certificate management

Video Streaming

// HLS video streaming configuration
{
  "cdn": "cloudfront",
  "format": "HLS",
  "qualities": ["720p", "1080p", "4K"],
  "edge_caching": true,
  "cache_duration": "7d"
}
CDNs enable:
  • Adaptive bitrate streaming
  • Reduced buffering
  • Lower latency for live streams
  • Global reach for content

Website Acceleration

<!-- Serve static assets from CDN -->
<link rel="stylesheet" href="https://cdn.example.com/styles/main.css">
<script src="https://cdn.example.com/js/app.bundle.js"></script>
<img src="https://cdn.example.com/images/hero.jpg" alt="Hero image">

API Acceleration

// Cache API responses at the edge
const response = await fetch('https://api.example.com/products', {
  headers: {
    'Cache-Control': 'public, max-age=3600'
  }
});

Software Distribution

CDNs excel at distributing:
  • Software updates
  • Mobile app bundles
  • Game patches
  • Operating system images

CDN Cache Control

HTTP Cache Headers

HTTP/1.1 200 OK
Cache-Control: public, max-age=31536000, immutable
ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4"
Expires: Wed, 21 Oct 2025 07:28:00 GMT
Last-Modified: Tue, 15 Nov 2024 12:45:26 GMT

Cache Invalidation

Content automatically expires after TTL:
Cache-Control: max-age=3600  # 1 hour

Cloud Gaming and Streaming

Cloud gaming uses CDN technology to provide users with high-quality, low-latency gaming experiences:

Low Latency

Edge servers reduce input lag for responsive gameplay

High Bandwidth

Deliver high-quality video streams for 4K gaming

Global Reach

Enable gaming from anywhere in the world

Scalability

Handle millions of concurrent players

Real-World CDN Architecture

Major CDN Providers

  • 300+ edge locations
  • Free tier available
  • DDoS protection included
  • Workers for edge computing
  • 450+ Points of Presence
  • Deep AWS integration
  • Lambda@Edge for compute
  • Pay-as-you-go pricing
  • 4,100+ PoPs worldwide
  • Enterprise-focused
  • Advanced security features
  • Media delivery expertise
  • Real-time purging
  • Edge computing platform
  • Instant configuration updates
  • Developer-friendly

Best Practices

Improper cache configuration can lead to serving stale content or unnecessary origin requests.
1

Set appropriate TTLs

Balance freshness with cache efficiency. Static assets can have longer TTLs (days/weeks), while dynamic content needs shorter TTLs (minutes/hours).
2

Use cache-friendly URLs

Include version numbers or content hashes in URLs for better cache control:
/assets/app.v2.1.5.js
/images/logo.a3f5c9.png
3

Implement cache warming

Pre-populate CDN caches with frequently accessed content before traffic spikes.
4

Monitor cache performance

Track key metrics:
  • Cache hit ratio
  • Origin offload percentage
  • Edge response times
  • Bandwidth savings
5

Secure your CDN

  • Enable HTTPS everywhere
  • Use signed URLs for protected content
  • Implement rate limiting
  • Configure WAF rules

Performance Optimization

<!-- Modern image formats -->
<picture>
  <source srcset="/cdn/image.avif" type="image/avif">
  <source srcset="/cdn/image.webp" type="image/webp">
  <img src="/cdn/image.jpg" alt="Optimized image">
</picture>
  • Automatic format conversion
  • Responsive image sizing
  • Lazy loading support
CDNs are transforming how we access and consume digital content, providing faster, more reliable, and more immersive experiences for users worldwide.

Next Steps

Redis Caching

Learn about in-memory caching with Redis

Caching Strategies

Explore different caching patterns

Cache Eviction

Understand cache eviction policies

Build docs developers (and LLMs) love