A Content Delivery Network (CDN) is an system of geographically distributed servers that optimize the delivery of content by caching it close to users. While often associated with static assets like CSS and images, CDNs are fundamental for delivering bandwidth-intensive content like videos.

How does a CDN work?

A content delivery network relies on three types of servers.

  • Origin servers. Origin servers contain the original versions of content and they function as the source of truth. Whenever content needs to be updated, changes are made on the origin server. An origin server may be owned and managed by a content provider or it may be hosted on the infrastructure of a third-party cloud provider like Amazon’s AWS S3 or Google Cloud Storage.
  • Edge servers. Edge servers are located in multiple geographical locations around the world, also called “points of presence” (PoPs). The edge servers within these PoPs cache content that is copied from origin servers, and they are responsible for delivering that content to nearby users.
  • DNS servers. Domain Name System (DNS) servers keep track of and supply IP addresses for origin and edge servers. When a client sends a request to an origin server, DNS servers respond with the name of a paired edge server from which the content can be served faster.

Tip

When a user requests access to content on an origin server, they are redirected to a cached copy of the content on an edge server that’s geographically close to them. When cached content is out of date, the edge server requests updated content from the origin server. CDN edge servers are owned or managed by the CDN hosting provider.

CDN and Video Delivery

For videos, the CDN works hand-in-hand with transcoding and Adaptive Bitrate Streaming. Videos are broken into small time-based chunks (e.g., 5 seconds) in different resolutions and bitrates. These chunks are cached independently, allowing CDNs to serve only the necessary portions of a video.

When a user starts streaming, the CDN initially fetches the required chunks from the origin server or another CDN node. As more users in the same geographic region request the same content, these chunks are cached locally at the edge server, ensuring subsequent requests don’t reach the origin. This is particularly efficient for popular videos, as hot content remains cached near users.

Intelligent Cache Management

CDNs do not cache every piece of content indefinitely. Instead, they use policies like least recently used (LRU) to evict stale items and ensure the cache contains high-demand content. For large videos, CDNs often cache individual chunks rather than the entire file, enabling finer-grained cache utilization.

CDNs also rely on cache hierarchies:

  • Edge Servers: Closest to the user, they cache high-demand content.
  • Regional PoPs (Points of Presence): Act as intermediaries, reducing the need for frequent origin server requests.
  • Origin Server: The final source of truth, accessed only when content is missing from the CDN.

Dynamic Content and CDNs

For static assets like CSS, caching is straightforward. For videos or other dynamic content, CDNs must integrate with the system to handle tokenized or authenticated requests. For example:

  • A signed URL might be used to ensure only authorized users can access video chunks.
  • The CDN validates the token before serving the content, ensuring access control while maintaining performance.

CDNs and Network Optimization

CDNs use advanced routing algorithms to determine the best path for delivering content. They consider real-time factors like server load, network congestion, and latency. Additionally, many CDNs employ TCP optimizations and QUIC (Quick UDP Internet Connections) to reduce round-trip times and improve streaming performance.

For video delivery, the use of HTTP/2 or HTTP/3 (QUIC) can be significant. These protocols support multiplexing, allowing multiple chunks to be fetched over a single connection, reducing latency during playback.

Specific CDN Features for Video Platforms

  1. Origin Shielding: A specific layer within the CDN prevents repeated requests to the origin by centralizing cache misses at a designated intermediate node.
  2. Partial Caching: For adaptive bitrate streaming, CDNs cache video chunks independently. Even if a 1080p chunk isn’t cached, the 720p version might be, reducing the load on upstream servers.
  3. Real-Time Reporting: CDNs continuously monitor and report metrics like cache hit ratios, bandwidth usage, and latency. These insights help video platforms optimize their infrastructure.

Example: YouTube’s CDN-Like System

YouTube combines traditional CDNs with its own proprietary Edge Network, where videos are stored and streamed from strategically located data centers. These centers work like a CDN but with tighter integration into YouTube’s transcoding pipeline and video metadata.

When a video becomes popular, it is replicated across multiple edge locations to ensure availability. The system predicts user demand based on viewing trends and preemptively caches videos in regions likely to experience spikes.

Advanced Topics

For deeper technical implementation, CDNs employ concepts like:

  • Content Invalidation: Mechanisms to purge outdated or removed content from edge caches.
  • Geo-Blocking: Configurations to restrict access to content based on geographic location, often tied to licensing agreements.
  • Traffic Steering: Balancing loads between servers and routing users to alternate locations during server outages or congestion.