awesome-everything RU
↑ Back to the climb

Networking & Protocols

Anycast and GeoDNS: routing to the nearest edge

Crux How the same IP address advertised from 300 cities and geography-aware DNS cooperate to send every user to their closest CDN edge server.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at middle altitude — in the sky
◷ 10 min

You want every user — whether in London, Tokyo, or São Paulo — to hit the nearest CDN server automatically, without manually configuring routes or maintaining separate URLs per region. Two mechanisms solve this: Anycast and GeoDNS. They work differently and are often used together.

Anycast IP routing

With Anycast, the CDN operator announces the same IP address (e.g. 93.184.216.1) from multiple geographic locations simultaneously via BGP. BGP routing selects the “nearest” edge location as measured by AS path length or hop count. When a user makes a request, their local router sends it to the closest POP advertising that IP — no special DNS needed, just standard BGP routing.

Upside: works automatically; any network-level change (POP added, withdrawn) takes effect within BGP convergence time (seconds to minutes). Downside: BGP “nearest” is hop-count nearest, not latency-nearest. Two cities equidistant by hops can differ by 50 ms of real latency.

GeoDNS

With GeoDNS, the CDN’s authoritative nameserver returns different A records based on the geographic location of the resolving nameserver. A query from a London resolver returns a London edge IP; a Tokyo resolver gets Tokyo. This gives the operator explicit control over routing — you can steer different regions to different POPs manually.

The resolver vs. the user. GeoDNS sees the resolver’s IP, not the browser’s. A user in Toronto using Google’s 8.8.8.8 resolver gets the IP for whichever region Google’s DNS server appears to come from — often Mountain View, CA — which may route them to a US POP instead of a Toronto one. That’s suboptimal.

EDNS Client Subnet (ECS) partially fixes this: resolvers that opt in send the user’s /24 subnet prefix alongside the DNS query, letting the authoritative server return a location-aware IP. Cost: the user’s subnet prefix travels up the DNS delegation chain, reducing privacy. Apple’s iCloud Private Relay and Cloudflare’s 1.1.1.1 disable ECS for this reason, accepting slightly suboptimal routing.

Anycast vs. GeoDNS comparison
Anycast selection basis
BGP AS path length (hop count)
GeoDNS selection basis
Resolver IP geolocation
Anycast BGP convergence on POP change
Seconds to minutes
GeoDNS TTL (typical)
30–60 s for fast steering
EDNS Client Subnet granularity
/24 prefix (user subnet)
Cloudflare smart routing (Argo) p95 saving
30–50% on intercontinental paths

How CDNs combine both

Most large CDNs use Anycast at the IP layer and GeoDNS on top to combine their strengths. Anycast handles DDoS absorption well — volumetric attacks are spread across every POP advertising the IP. GeoDNS provides explicit failover: withdraw a POP from DNS when unhealthy, so new connections stop arriving within one DNS TTL.

Why this works

Why Anycast alone is not enough for CDNs. Anycast routes by BGP metrics, not by actual latency. A user’s ISP might peer with a CDN POP that is geographically distant but has a short AS path. Cloudflare Argo Smart Routing and AWS Global Accelerator add a measurement layer: they probe actual round-trip latency from many POPs continuously and route traffic over a private backbone (bypassing the public internet) to the lowest-latency POP. Typical saving: 30–50% reduction in p95 latency on intercontinental hops. Cost: per-GB premium pricing for backbone traversal. Worth it for latency-sensitive APIs; usually overkill for static-asset delivery.

Quiz

A user in Toronto uses 8.8.8.8 as their DNS resolver. Why might they land on a US West Coast CDN POP instead of a Toronto one?

Quiz

What is the main limitation of pure Anycast routing for CDN proximity?

Trace it
1/4

Trace how a London user reaches the correct CDN edge with GeoDNS.

1
Step 1 of 4
Browser resolves cdn.example.com. Which DNS server does the query ultimately reach?
2
Locked
The authoritative server sees the query from a London-area resolver IP. What does it return?
3
Locked
Browser connects to that London edge IP via TCP + TLS. What is the advantage?
4
Locked
Six months later, the operator withdraws the London POP for maintenance. How long until users stop landing there?
Order the steps

Order a request path using Anycast routing (no GeoDNS involved):

  1. 1 Browser issues DNS query — resolver walks to CDN authoritative NS
  2. 2 Authoritative NS returns the single Anycast IP (same IP for all regions)
  3. 3 Browser's TCP SYN packet enters the internet with that destination IP
  4. 4 ISP routers apply BGP forwarding: forward toward the CDN AS advertising the shortest path
  5. 5 Packet arrives at the CDN POP with the shortest BGP path from this ISP
  6. 6 TLS handshake + HTTP request completes at that POP
Recall before you leave
  1. 01
    Explain in two sentences why Anycast routing and GeoDNS solve the same problem but fail in different ways.
  2. 02
    What does EDNS Client Subnet do, and what is the privacy cost?
  3. 03
    A CDN operator discovers their London POP is experiencing high packet loss. How do they stop new users from landing there, and how fast does it take effect?
Recap

Anycast and GeoDNS are the two proximity routing mechanisms CDNs use to send every user to the nearest edge server. Anycast advertises one IP from all POPs and lets BGP pick the closest by hop count — automatic and DDoS-resilient, but not perfectly latency-optimal. GeoDNS returns different A records per resolver geography — explicit and fast to change, but only as accurate as the resolver’s location relative to the user. Most CDNs combine both: Anycast for scale and DDoS absorption, GeoDNS for failover control, and optionally smart routing (Cloudflare Argo, AWS Global Accelerator) over a private backbone to correct for BGP’s latency blindspot.

Connected lessons
appears again in162
Continue the climb ↑Tiered cache and Cache-Control
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.