System Design

Unpacking CDN Architecture: How Global Content Delivery Works Under the Hood

Content Delivery Networks (CDNs) are the invisible backbone of the modern web, ensuring that millions of users access data with minimal latency. While many developers treat CDNs as a simple "plug-and-play" service, understanding their underlying architecture is critical for system designers aiming to build high-performance, scalable applications. This post breaks down the core components of a CDN, from DNS resolution to edge caching and origin offloading.

The Core Components of a CDN

A typical CDN architecture consists of three primary layers: the Edge Network, the Origin Server, and the Control Plane.

1. Edge Nodes (Points of Presence)

The edge is where the magic happens. Edge Nodes, also known as Points of Presence (PoPs), are strategically located data centers around the world. When a user requests a resource, the request is routed to the nearest edge node based on latency and network health. These nodes cache static assets (images, CSS, JS) and sometimes dynamic responses to reduce load on the origin server.

2. The Origin Server

The origin is your primary data source, usually hosted in a central data center or cloud region. In a well-designed CDN setup, the origin should be protected. Direct traffic to the origin should be minimized or blocked to prevent DDoS attacks and reduce infrastructure costs. The origin serves as the authoritative source for content that is not yet cached at the edge.

3. Anycast DNS and Load Balancing

CDNs rely heavily on Anycast routing. Instead of assigning unique IP addresses to each server, multiple servers across the globe share the same IP address. When a user sends a request, the internet's Border Gateway Protocol (BGP) routes the packet to the nearest edge node that advertises that IP.


// Example DNS Response for a CDN-enabled domain
$ dig example.com

; <<>> DiG 9.18.13 <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12345
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1

;; QUESTION SECTION:
;example.com.			IN	A

;; ANSWER SECTION:
example.com.		300	IN	A	203.0.113.10
example.com.		300	IN	A	198.51.100.20
example.com.		300	IN	A	192.0.2.30
example.com.		300	IN	A	198.18.0.40

Caching Strategies and Invalidation

Efficient caching is the primary value proposition of a CDN. The architecture supports various cache-control headers to dictate how long objects should be stored at the edge.

  • TTL (Time To Live): Determines how long the edge node keeps the object before requesting a fresh copy from the origin.
  • Cache Key: Typically composed of the URL path, query string, and headers like User-Agent or Accept-Language.
  • Invalidation: A mechanism to purge cached content immediately when the origin content changes. This is often triggered via API calls to the CDN provider.

# .htaccess or Nginx configuration for setting cache headers
AddHeader Cache-Control "max-age=31536000, public, immutable"

# For Nginx:
location /static/ {
    expires max;
    add_header Cache-Control "public, immutable";
}

Dynamic Content and Origin Shielding

Not all content is static. For dynamic API responses, CDNs employ "Origin Shielding." In this model, a tier of intermediate edge nodes acts as a proxy for the global edge nodes. Only the shield layer makes requests to the origin. This significantly reduces the number of concurrent connections to the origin server, preventing bottlenecks during traffic spikes.

Security Considerations

CDNs are the first line of defense against DDoS attacks. By absorbing traffic at the edge, they mitigate volumetric attacks (UDP floods, ICMP floods) and layer 7 attacks (HTTP floods). Additionally, CDNs provide SSL/TLS termination, meaning the encrypted handshake happens at the edge, and traffic between the edge and the origin can be encrypted using mutual TLS (mTLS) or remain internal to the CDN's private network.

Conclusion

Understanding CDN architecture allows developers to make informed decisions about cache policies, security configurations, and infrastructure scaling. By leveraging edge caching, Anycast routing, and origin shielding, CDNs transform global web applications into fast, resilient, and secure systems. As edge computing grows, the boundary between the CDN and the application layer will continue to blur, making this knowledge even more vital for modern system designers.

Share: