Skip to main content
networking

BGP + Anycast internals

9 min read
Fully authored

How the internet's routing table serves the same IP from 300 places at once.

BGP (Border Gateway Protocol) is how the internet routes between autonomous systems. Anycast is announcing the same IP prefix from MULTIPLE data centers — the routing table auto-picks the closest one for each user. Every major CDN uses this.

How Anycast works

  1. You own IP 1.1.1.1 (real Cloudflare example).
  2. You announce 1.1.1.1/32 from your DC in Frankfurt, Ashburn, Singapore, Sydney — all simultaneously via BGP.
  3. Each router in the internet gets a route to 1.1.1.1 for each announcement. It picks the shortest AS-path.
  4. Users in Europe hit Frankfurt. Users in Asia hit Singapore. Same IP, different physical box.

Why it works for DNS + CDNs + DDoS mitigation

  • DNS resolution: sub-15ms globally. Cloudflare 1.1.1.1 uses this.
  • CDN edge: nearest POP by BGP path. No custom routing logic.
  • DDoS mitigation: attack traffic naturally splits across POPs — a 400 Gbps attack against 200 POPs = 2 Gbps per POP. Diluted.

The trade-off — TCP is tricky

Anycast works great for UDP (DNS). For TCP, you need session affinity — the same client must reach the same server for the duration of the connection. Solved by: BGP path stability (rare flaps), consistent hashing at the edge, or session state stored in a shared cache. Cloudflare + Fastly + Google all do this.

Real deployment sizes

Cloudflare 1.1.1.1: 300+ POPs, sub-15ms globally, ~15% of DNS queries
Google 8.8.8.8: hundreds of POPs via BGP anycast
Akamai: 4000+ POPs, primarily HTTP anycast
Fastly + Cloudflare + AWS CloudFront: all anycast at the front door

Practice what you just read

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