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
- User resolves a CNAME — e.g.,
cdn.example.commight resolve toedge-01.lax.cdnprovider.net. - DNS returns an edge location — the DNS resolver may return the IP of the geographically closest edge server.
- Edge cache lookup — the edge server checks its cache. If the content is there (a cache hit), it serves it immediately.
- 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
| Anycast | CDN | |
|---|---|---|
| Routing | BGP selects the nearest replica | DNS returns the nearest edge server |
| Content | Same IP, same service | Edge servers cache specific content |
| Use case | DNS root servers, CDN entry points | Web 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.