Traffic and messaging
Global load balancing
How DNS and anycast steer a user to the nearest healthy region, and why DNS failover can take minutes.
Global load balancing decides which region a user's request reaches first. Two tools do most of the work. DNS steering answers each lookup with the IP of a nearby, healthy region. Anycast announces one IP address from many places, so internet routing delivers each packet to the nearest site.
Concept
A resolver is the server your device asks to turn a name into an IP address. It caches each answer for the record's TTL (time to live), measured in seconds. A short TTL means faster changes and more lookups.
The big idea
DNS steering is like a phone directory that gives you the number of the nearest branch. Everyone copies the number down and keeps calling it, even after that branch closes, until the copy expires. That is why DNS failover is slow.
Anycast is like a chain of shops that share one phone number. The phone network connects each caller to the nearest shop automatically. If one shop closes, calls go to the next one, and nobody has to update a copied number.
The analogy breaks in two places. Anycast follows network topology, not distance on a map. And TCP needs every packet of a connection to reach the same site, so anycast suits short connections best.
Walking through it
Here is DNS failover with a 60-second TTL. Region A fails at time zero.
t=0 region A fails, its health check marks it down
t=0-60s resolvers still hand out region A's IP from their caches
t=60s+ new lookups return region B; slow resolvers may lag longerA 60-second TTL is a common compromise between fast failover and DNS query load. Some resolvers and clients ignore the TTL, so the tail can be longer. DNS also routes by the resolver's location, not the user's. EDNS Client Subnet helps by passing part of the user's address along.
Anycast failover takes as long as BGP, the protocol that routes between networks, needs to converge. That is typically seconds, with no caches to wait out. Cloudflare, Google's global front end and most CDNs use it at their edge. Because each TCP connection needs all its packets at one site, the edge proxy terminates the connection and forwards the request to a region over a private network.
The full path usually stacks these pieces:
Global routing picks the region. The regional balancers described in load balancing pick the instance. The CDN page covers what the edge does besides routing, and edge and traffic covers the cloud networking side.
Common mistakes
- Expecting DNS failover to be instant. Caches and ignored TTLs keep old answers alive.
- Routing by the resolver's location. A user far from their resolver can land in the wrong region. Pass the client subnet where you can.
- Using anycast for long connections without an edge proxy. Routing can change during a long connection, so terminate connections at the edge.
Check yourself
-
Why doesn't a 60-second TTL guarantee failover within 60 seconds?
Some resolvers and clients cache longer or ignore the TTL, so some traffic keeps reaching the failed region.
-
Why does anycast suit short connections better?
Each TCP connection needs all its packets at one site. Long connections can break if routing shifts, so an edge proxy usually terminates them.
Key takeaways
- DNS steering is simple and works with any protocol, but failover waits on caches.
- Anycast fails over in seconds because it doesn't depend on caches.
- Anycast pairs with an edge proxy, which terminates connections and forwards them over a private network.
- Global routing sends a user to a region, and regional balancers then pick the instance.
Further learning
Next: multi-region architecture, which covers how regions split traffic and data.
Related
Load balancing and proxies
How a load balancer chooses which server gets each request, and how a badly set up balancer can cause the outage it was meant to prevent.
Multi-region architecture
Active-passive, active-active and cell-based designs for latency, disaster tolerance and data residency, with the recovery, consistency and cost trade-offs each one carries.
CDNs and the edge
Serve content from points of presence near users. A CDN cuts latency, absorbs attacks and cuts bandwidth costs, and its cache keys, headers and purge rules decide how well it works.