Skip to main content

Global & DNS-Level Load Balancing (GSLB, Anycast)

Level 4: Level 4: Scaling Compute & Traffichard30 mingslbanycastmulti-region

GeoDNS steers coarsely but is TTL-bound; anycast plus BGP withdrawal gives seconds-scale failover; active-active regions need headroom to absorb a lost region.

Steer users to the nearest healthy region, and fail fast

Once your product serves users on multiple continents from multiple regions, you need a way to steer each user to a nearby healthy region and, when a region catches fire, to pull all traffic off it fast. There are two distinct mechanisms, and interviewers want you to know they operate at different layers.

Check yourself
A region dies and you flip its DNS record to point elsewhere. The record's TTL is 30 seconds. How long until the last client stops hammering the dead region?

GeoDNS / DNS-based GSLB steers at name resolution. When a client resolves api.example.com, an authoritative DNS service (Route 53, NS1, Akamai) returns different IPs based on the resolver's location or measured latency. You get geo-routing, latency-based routing, weighted records (send 10% to a new region for a canary), and health-checked failover (stop handing out a region's IP once its health check fails). The catch is that DNS is a caching system. Every answer carries a TTL, and resolvers, OS stub resolvers, and browsers cache it. Even a 30 to 60 second TTL means some clients keep hitting a dead region for a minute or more after you flip the record, and some misbehaving resolvers ignore short TTLs entirely. So DNS failover is never instant, and that single fact is the most-probed point in this topic.

Anycast steers at the network layer. You announce the same IP address from many points of presence via BGP. The internet's routing fabric delivers each client's packets to the topologically nearest PoP announcing that prefix. Withdraw the BGP announcement at a failing PoP and traffic reconverges to the next-nearest one in seconds, with no DNS change and no client-side caching to wait out. ECMP spreads flows across equal-cost paths. The subtlety: plain ECMP rehashes flows when the server set changes, which breaks in-flight connections. Production anycast load balancers (Google's Maglev, AWS Hyperplane) use consistent hashing so a backend change only remaps a small fraction of connections.

Check yourself

Two steering mechanisms, two layers. Sort each property.

Failover speed bounded by resolver caching
Withdraw an announcement and traffic reconverges in seconds
Weighted records sending 10 percent of users to a new region
The same IP address announced from many points of presence
Needs Maglev-style consistent hashing so a backend change does not break in-flight connections

The two combine in practice: anycast to the nearest edge/CDN PoP terminates TLS and absorbs the connection close to the user, then the edge forwards over warm long-haul connections to a healthy origin region chosen by GSLB.

User -> [Anycast IP, BGP -> nearest PoP] -> edge TLS terminate
     -> GSLB picks healthy origin region -> origin
  fail a region: withdraw BGP (seconds)  |  flip DNS (minutes, TTL-bound)

Active-active vs active-passive, and draining

Active-active runs live traffic in every region, so failing one out is just shifting its share onto the survivors (which must have the headroom to absorb it). Active-passive keeps a warm standby that only takes traffic on failover: simpler but wastes capacity and has a colder failover path. To drain a region cleanly you stop sending it new traffic (lower its DNS weight to zero or withdraw its anycast announcement), let in-flight requests finish, then take it down.

Interview nuance: if you say "DNS failover, done" you will be asked "how long until the last user leaves the dead region?" The honest answer is bounded by TTL plus resolver misbehavior, which is why anycast (BGP withdrawal) or connection-level draining is what actually gives you sub-minute regional failover.

Recap: use GeoDNS for coarse region steering and anycast plus BGP for fast, cache-free failover, keep connections stable with Maglev-style consistent hashing, and never claim DNS failover is instant because resolver caching bounds it.

Check yourself
Region us-east is failing and the interviewer wants traffic off it in under a minute without dropping in-flight requests. What is the strongest sequence?

Apply

Your turn

The task this lesson builds to.

Design how a global user is routed to the nearest healthy region and how you fail an entire region out in under a minute.

Think about

  1. How do GeoDNS and anycast differ for steering?
  2. Why does client DNS caching limit failover speed?
  3. Active-active vs active-passive: how do you drain a region?

Practice

Make it stick

A second problem on the same idea, so it survives past today.

Design global traffic steering and 60-second regional failover for a payments API like Stripe running active-active in five regions at 200K requests/sec, where a region can go unhealthy partially (elevated p99 and error rate, not a clean crash) and some tenants are contractually pinned to an EU region for data residency.

Think about

  1. How do you detect and respond to a gray failure that never trips a binary health check?
  2. What must routing never do with EU-pinned tenants, even during failover?
  3. What keeps retried payment requests from double-charging across regions?