Video in progress

In a system running in several regions, how do you decide which region to route a user request to: GeoDNS, anycast or a global load balancer?

GeoDNS is simple, but failover is slow because of DNS caching, and it guesses location by the resolver. Anycast and a global L7 load balancer give fast failover and health-based routing. The decision also depends on where the data lives: you may need to send the request not to the nearest region but to the one that owns the data.

📖 Answer

First question: are the regions equal? If a user's data lives in a "home region" (for data residency, or to avoid write conflicts), "send to the nearest region" isn't enough, because the write still has to go to the owner.

GeoDNS. DNS returns different IPs depending on the location of the resolver that asks. It's simple and works with any protocol. But there are two problems:

  • even with a TTL of 60 s, some resolvers and clients hold the answer longer, so failover takes minutes, and for some even more;
  • location is determined by the resolver, not the user; EDNS Client Subnet softens this partly.

Anycast. One IP is announced from several places over BGP, and traffic goes to the nearest one by routing. Failover means withdrawing the announcement, which is fast. CDN and DNS providers work this way; building it yourself needs serious networking experience, so in practice you get it through the cloud's global LB or a CDN.

Global L7 load balancer / edge. TLS terminates at the edge, and the request travels over the provider's network to the region. It routes by region health and latency, failover takes seconds, and you can shift traffic by percentage (region migration or canary). The cost is lock-in to the provider and one more critical layer.

Combining with a home region:

  • the edge brings the request to a nearby region, which forwards it over the internal network to the owner based on home_region in the token; or the client is given a region domain (eu.api.example.com) at login;
  • the read endpoints that can be answered from a local replica are marked separately.

I test the plan by measuring: artificially make a region "sick" and see how long it takes for traffic to shift and with how many errors. A plan that ignores DNS caching usually gets exposed right there. And whether the remaining regions can carry the traffic that shifts to them: capacity is part of the plan too.