Skip to main content
networking

CDN and Anycast

12 min read
Fully authored

Serving the same IP from many places at once.

In 1998, MIT professors Tom Leighton and Danny Lewin founded a company to solve a specific problem: the internet couldn't handle flash crowds. When a story went viral — a Yahoo homepage feature, an Olympic result — the origin server would melt under the sudden load. Every user, worldwide, hit the same rack of servers. Leighton and Lewin's idea was to replicate the content to edge servers physically close to users. The company they founded was Akamai.

Today, every major website relies on CDNs. Cloudflare has 300+ data centers. Akamai has 4000+. Fastly, Amazon CloudFront, Google Cloud CDN, Alibaba, Bunny CDN, each with their own edge networks. Together they absorb the majority of internet traffic — most requests to popular sites never reach the origin. When you load Netflix, ~99% of the bytes come from an Open Connect Appliance embedded inside your ISP's network. Origin is barely touched.

CDNs work on a beautiful trick: Anycast at Layer 3. The same IP address is announced from hundreds of physical locations via BGP. When your packet leaves your ISP, the internet's routing tables direct it to the closest instance. No DNS trickery required — the IP is the same everywhere. This concept extends beyond CDNs: Google DNS 8.8.8.8, Cloudflare 1.1.1.1, and the root DNS servers all run on Anycast.

The papers & standards

  • Karger et al. (1997) — "Consistent Hashing and Random Trees" (STOC). The paper that enabled Akamai's edge selection.
  • RFC 1546 (1993) — original Anycast proposal.
  • RFC 4271 (2006) — BGP-4, the routing protocol that makes Anycast work at internet scale.
  • Nygren, Sitaraman, Sun (2010) — "The Akamai Network." ACM SIGOPS. How Akamai routes billions of requests.

Anycast — the same IP, everywhere

Every host on the internet has one IP. Or so we're taught. Anycast breaks that: the same IP is announced from N different physical locations. When a packet is routed to that IP, the internet's BGP routing tables direct it to the topologically nearest instance — usually also the geographically nearest.

Anycast routing — step 1 of 5
Same IP 104.16.132.5, 4 different destinations.
World map (schematic)LondonTokyoSão PauloSydney104.16.132.5104.16.132.5104.16.132.5104.16.132.5
User in London types example.com — resolves to 104.16.132.5 (an Anycast IP). Packet enters the BGP routing tables.

This works because BGP routes are computed per-router. Each router sees multiple paths to the same destination IP and picks the one with the fewest AS hops. As long as each instance announces the route from a similarly-positioned network, traffic naturally lands nearby. No DNS decision required. Failover happens at the routing layer — if an instance goes offline, BGP withdraws its announcement and traffic reroutes to the next-closest one within seconds.

What a CDN actually does

A CDN is much more than a cache. Modern CDNs like Cloudflare and Fastly do:

Static asset caching
Images, CSS, JS, videos cached at edge. This is the classic use case.
Dynamic content acceleration
Even non-cacheable requests benefit from being routed via the CDN's optimized backbone (Cloudflare Argo, AWS Global Accelerator).
TLS termination
CDN handles the TLS handshake at edge, then keeps a persistent connection to origin. Users see fast TLS.
DDoS protection
Anycast absorbs volumetric attacks. WAF rules block application-layer attacks.
Web Application Firewall (WAF)
Filter malicious requests (SQLi, XSS, bot patterns) at edge before they hit origin.
Bot management
Distinguish humans from bots via fingerprinting, JavaScript challenges, CAPTCHA. Only Cloudflare-scale companies can do this well.
Edge compute
Run code at PoPs. Personalize responses, rewrite paths, do A/B tests without a round-trip to origin.
Image optimization
Serve WebP or AVIF instead of JPEG based on browser support. Resize on the fly. Compress.
Video streaming (HLS/DASH)
Serve video chunks from edge. Adapt bitrate based on measured throughput. Netflix and Twitch do this at massive scale.
Analytics + logs
Every request logged. Real User Monitoring (RUM). Cloudflare Radar exposes some of this publicly.

Cache hit vs miss — what happens on the edge

CDN cache flow — step 1 of 5
Cache hit vs miss, per-PoP behavior.
ClientNew YorkCDN EdgeMISS ✗Originhandling~50ms edge+ ~100ms origin
First user in NY requests /image.png. NY edge has no cached copy — cache miss. Edge forwards to origin.

On a cache hit, the CDN edge responds in <10ms — the request never touches your origin. On a cache miss, the edge fetches from origin, caches it, and returns it. A well-tuned CDN can have 95%+ cache hit rates for static assets — meaning your origin server carries 5% of the load a naïve architecture would need. That's the operational unlock.

Cache-Control — the language of caching

CDNs respect the Cache-Control HTTP header from your origin. Getting this right is what separates a 99% cache hit rate from 0%:

  • max-age=3600 — browsers may cache for 1 hour.
  • s-maxage=86400 — CDN edges specifically may cache for 24 hours. Overrides max-age for shared caches.
  • public — any cache may store. private — only the end-user browser (not CDN).
  • no-store — do not cache at all. no-cache — cache, but always revalidate with origin (via ETag).
  • stale-while-revalidate=60 — serve stale content while refreshing in the background. The killer feature that keeps origin load steady even during traffic spikes.

GeoDNS vs Anycast — the two edge-routing strategies

DimensionGeoDNSAnycast (BGP)
How user picks a PoPDNS resolver returns different A record per regionBGP routes packets to nearest instance of same IP
Failover speedTTL-bounded (~seconds to minutes)Sub-second (BGP withdrawal)
Client caching interferenceYes — resolver may cache stale IPNone — no DNS involvement per request
DDoS absorptionPoor — one target IP per regionExcellent — attack diffuses across all PoPs
Infrastructure requirementJust DNSBGP presence in every DC (needs peering)
Real usersAkamai (historically), Netflix Open ConnectCloudflare, Fastly, Google DNS 8.8.8.8, root DNS

Historically, DNS-based edge selection was more common (Akamai used it heavily). Modern CDNs (Cloudflare, Fastly, Bunny) overwhelmingly use pure Anycast. AWS CloudFront uses a hybrid: Anycast IPs, but with regional pool selection via internal routing.

DDoS absorption — the accidental superpower

Anycast turns out to be extraordinary at absorbing DDoS attacks. A single 1 Tbps attack against your origin would take you down. The same attack against Cloudflare's Anycast IP spreads naturally across 300+ data centers — each center sees ~3 Gbps, well within capacity. Cloudflare publishes reports of absorbing 26 Tbps+ attacks without customers noticing. This is the primary reason startups put Cloudflare in front of everything.

Applied in real systems — the CDN landscape

Cloudflare
Deep dive

Cloudflare — the biggest Anycast CDN

300+ data centers. Anycast for both cache + DNS + DDoS protection. Free tier absorbs 20% of internet traffic. Workers = compute at edge. R2 = S3-compatible object storage without egress fees. The all-in-one edge platform.

Read the deep dive →
Akamai
Deep dive

Akamai — the OG CDN

Founded 1998. 4000+ edge locations. Historically the enterprise choice — used by every major bank, broadcaster, and government. Hybrid DNS + Anycast routing. More features + complexity than modern CDNs.

Read the deep dive →
Fastly
Deep dive

Fastly — the developer-friendly CDN

Instant cache purging (typical <150ms globally). VCL config lets you write cache logic in code. Powers many major publishers, GitHub, Shopify, Stripe. In 2021 a Fastly outage briefly took down the New York Times, the UK government, Amazon.

Read the deep dive →
AWS CloudFront
Deep dive

AWS CloudFront — AWS's CDN

450+ edge locations. Tightly integrated with S3, ALB, Lambda@Edge, Route 53. Free tier: 1 TB/month. Sits behind most AWS-hosted sites. Standard for any AWS customer.

Read the deep dive →
Netflix Open Connect
Deep dive

Netflix Open Connect — the CDN inside ISPs

Netflix built their own CDN and physically places servers inside ISP networks (Comcast, BT, KDDI, etc.). ~99% of video bytes never cross the internet backbone. Open Connect Appliances (OCAs) are custom-built by Netflix.

Read the deep dive →
Google Edge
Deep dive

Google Global Cache — YouTube's edge

Google Global Cache (GGC) nodes live inside ISPs and serve YouTube, Google Play Music, Google Maps tiles. Same pattern as Netflix Open Connect but for Google. YouTube would be uneconomical without it.

Read the deep dive →
Cloudflare 1.1.1.1
Deep dive

1.1.1.1 — Anycast without a CDN

Not a CDN — a DNS resolver. But uses the exact same Anycast infrastructure. Your DNS query lands at the nearest Cloudflare data center. Same Anycast is what makes 8.8.8.8 (Google) fast too.

Read the deep dive →
Root DNS servers
Deep dive

Root DNS — Anycast at internet scale

There are 13 root servers named a through m. Each is actually an Anycast constellation of hundreds of instances. j.root-servers.net has 200+ physical instances worldwide, all announcing the same IP.

Read the deep dive →
Bunny CDN
Deep dive

Bunny — the underdog cheap CDN

Founded 2015 in Slovenia. Aggressive pricing ($0.01/GB in some regions). 100+ PoPs. Popular for hobby projects, indie SaaS. Good example that CDN infrastructure is now commoditized.

Read the deep dive →
Cloudflare Workers, Fastly Compute@Edge, Lambda@Edge
Deep dive

Edge compute — logic at the CDN

Modern CDNs let you run code at the edge. Rewrite requests, A/B split traffic, generate personalized responses without hitting origin. Cloudflare Workers (V8 isolates), Fastly Compute@Edge (WASM), AWS Lambda@Edge (containers).

Read the deep dive →

Key takeaways

  • A CDN caches your content at edge servers physically close to users. Reduces origin load 20-100x. Reduces user latency 5-10x.
  • Anycast (Layer 3) is the routing trick that makes it work. Same IP announced from many places via BGP; each user gets routed to the closest.
  • Cache-Control headers from your origin drive CDN behavior. Get them right or you'll have 0% cache hit rate. s-maxage and stale-while-revalidate are the operator's superpowers.
  • Anycast is a DDoS shield. A 1 Tbps attack against a 300-PoP Anycast is 3 Gbps per PoP — easily absorbed. Origin protection is often the #1 reason to adopt a CDN.
  • Netflix Open Connect + Google Global Cache extend the CDN concept: physical hardware inside ISP networks. Nearly all bytes are served from inside the last mile.
  • Edge compute (Cloudflare Workers, Fastly Compute) blurs the CDN + application server line. Personalized responses without round-tripping to origin.
  • Every serious system-design answer at global scale starts with "CDN in front of everything."

References

  • Karger et al. (1997) — Consistent Hashing. The Akamai foundation.
  • Nygren, Sitaraman, Sun (2010) — The Akamai Network. ACM SIGOPS.
  • Adhikari et al. (2012) — "Unreeling Netflix." Analysis of Netflix's CDN.
  • Cloudflare Radar — public traffic analytics at radar.cloudflare.com.
  • RFC 4271 — BGP-4.

Practice what you just read

Every foundation concept has a companion quiz to close the loop.