The Runtime Theory
Networking

CDNs and Anycast Routing

How content delivery networks place edge servers near users and how anycast uses BGP to route to the nearest replica.

The Runtime Theory Team6 min read#cdn#anycast#routing#performance
▸ On this page

CDNs and Anycast Routing

Content Delivery Networks (CDNs)

A CDN is a globally distributed network of edge servers that cache content close to users. When a user requests a resource, the CDN serves it from the nearest edge location rather than the origin server, reducing latency and offloading the origin.

How CDNs Work

  1. User resolves a CNAME — e.g., cdn.example.com might resolve to edge-01.lax.cdnprovider.net.
  2. DNS returns an edge location — the DNS resolver may return the IP of the geographically closest edge server.
  3. Edge cache lookup — the edge server checks its cache. If the content is there (a cache hit), it serves it immediately.
  4. Cache miss — the edge server fetches from the origin (or a parent edge), caches it, and serves the user. Subsequent requests hit the cache.

Cache Invalidation

CDNs use TTL (time-to-live) to determine how long to cache content. After the TTL expires, the next request triggers a fresh fetch from origin. For content that changes frequently, invalidation APIs can purge the cache proactively.

Anycast Routing

Anycast is a network addressing and routing strategy where the same IP address is assigned to multiple servers in different locations. When a client connects to an anycast address, BGP routes the connection to the "nearest" server (by hop count, not geographic distance).

Anycast vs. CDN

AnycastCDN
RoutingBGP selects the nearest replicaDNS returns the nearest edge server
ContentSame IP, same serviceEdge servers cache specific content
Use caseDNS root servers, CDN entry pointsWeb assets, videos, API responses

Anycast is often combined with CDNs: an anycast address serves as the entry point, and the edge server then serves cached content.

Edge Computing

Modern CDNs extend beyond caching — they run compute at the edge. Edge functions execute application code (authentication, A/B testing, image resizing) at the edge location, reducing round-trip latency to the origin.

Performance Impact

A well-configured CDN can reduce latency by 50–90% for static content and 20–50% for dynamic content. The first byte time (TTFB) is dominated by the TCP and TLS handshake cost, which is why HTTP/3 (zero-RTT handshake) and connection reuse are critical.

Read: HTTP/2 Multiplexing · Review: TCP Transport

Not started

Sign in to save your learning progress.

Sign in to save