Course map

Topic 094 / Advanced

Global traffic routing: GeoDNS and Anycast

Chapter 6.3 · Scaling Services

What and why

Load balancing (→ 92, → 93) distributes requests across instances within one site; global traffic routing decides which site a request reaches in the first place, across regions or data centers. GeoDNS answers a DNS query (→ 26) differently depending on the resolver's apparent location, pointing different users at different regional IPs. Anycast announces the same IP address from many physical sites simultaneously and lets internet routing (BGP) deliver each packet to whichever announcing site is network-closest. Boundary: this topic is steady-state routing mechanics — what decides which site a request lands on right now; failover orchestration when a region goes down is → 196. Builds on: → 26 (DNS).

Diagram

GeoDNS                                  Anycast
───────                                 ───────
user in EU ──DNS query──► resolver      user in EU ──packet──► nearest BGP-announcing
             returns EU IP                                      site (EU) — same IP
user in US ──DNS query──► resolver      user in US ──packet──► nearest BGP-announcing
             returns US IP                                      site (US) — same IP

How it works

  1. GeoDNS: a DNS server holds multiple records per name, one set per region, and answers each query based on the requester's (or their resolver's) apparent location — the "same name" resolves to different IPs for different users.
  2. GeoDNS decisions are made once, at resolution time, then cached for the record's TTL (→ 85) — a user keeps hitting the region they resolved to until that TTL expires and they re-resolve.
  3. Anycast: the same IP is announced from multiple physical locations; standard internet routing treats this as many paths to the same address, and each router forwards toward whichever announcing site its routing table says is closest — no DNS step and no per-user caching involved.
  4. Because Anycast routes at the network layer, a change (a site withdrawing its announcement) propagates through routing tables without waiting for any DNS cache to expire — often faster failover than GeoDNS's TTL-bound reaction.
  5. Both reduce latency by routing to whichever site is topologically closer — the same goal as a CDN's edge PoPs (→ 89) one layer up, applied to live application traffic instead of cached content.

Practical example

(numbers illustrative). A service has regions in the EU and US, each 10 ms from local users and 120 ms from the other region's users. With a single global IP and no location-aware routing, a US user randomly routed to the EU region pays 120 ms instead of 10 ms. With GeoDNS or Anycast routing each user to their nearer region, essentially all users pay ~10 ms instead of a mix of 10 ms and 120 ms — the saving is the full 110 ms gap for every request that would otherwise have been misrouted.

When to use it

  • Use GeoDNS when regions are independent deployments and a simple, well-understood DNS-based mechanism is enough — easy to reason about, bound by DNS TTL for reaction speed.
  • Use Anycast when faster reaction to a site disappearing matters, or routing needs to happen below the DNS layer.
  • Avoid building custom global routing logic before checking whether GeoDNS alone meets the latency and failover-speed target.
  • Failure scenarios: a GeoDNS record with a long TTL meaning a failed region keeps receiving traffic for as long as cached answers remain valid; a resolver reporting a location that doesn't match the real user's location, misrouting them; Anycast routing a connection toward a site based on a BGP path that changes mid-connection, breaking a long-lived stateful connection that assumed one site for its whole life (→ 91).
  • Simpler alternative: a single region, if latency to the farthest expected user is within the stated requirement — global routing is a cost paid only once more than one region exists for genuine reasons.

Practice

(decision kind — paper/trace exercise; 15–20 min, multi-site mechanics have no single-node lab equivalent).

  1. Given three regions and their pairwise cross-region latencies, and a traffic split by geography, compute mean latency with and without location-aware routing, mirroring the practical example's arithmetic with your own numbers.
  2. Decide, for a single-region startup and a global service with regions on three continents, whether GeoDNS, Anycast, or neither fits — justify from reaction-speed-to-failure and operational complexity.
  3. Explain, in one paragraph, why a long DNS TTL is a bad fit for failover-sensitive GeoDNS routing but may be fine for ordinary latency-based routing.

Done when your computed mean latency with location-aware routing matches the arithmetic method shown above, applied to your own numbers.

Shared lab setup

Key takeaway

GeoDNS routes at the name-resolution layer and is bound by DNS TTL; Anycast routes at the network layer and reacts as fast as BGP converges — both exist to put a user's traffic at the nearest healthy site. Done when you can: compute the latency cost of misrouted traffic and name which mechanism reacts faster when a site fails. Used next in → 196 (multi-region traffic and failover, the failure-handling half of this topic).

References

None — this topic makes no external claims.

Source directory

Search the guide