Sub topic 4
Routing users to regions: DNS, anycast and global load balancing
This chapter assumes you know basic DNS (records, TTLs, resolvers), what a load balancer does, and why a service might run in more than one region. It covers how a user's request reaches a region. Health-based failover has its own chapter.
The routing problem
In an active-active design every region serves live traffic. Something must decide which region handles each request. That decision should favor low latency, avoid unhealthy regions, and sometimes respect data rules. There are three common mechanisms.
| Mechanism | Decision point | Failover speed | Main limit |
|---|---|---|---|
| DNS-based routing | Resolver answer | Bounded by TTL and resolver caching | Clients and resolvers may ignore TTLs |
| Anycast | Network (BGP) routing | Seconds to minutes | Little control over where traffic goes |
| Global load balancer | Edge proxy | Seconds | Extra hop and vendor dependence |
DNS-based routing
With DNS routing, the name api.example.com returns a different address depending on who asks. Route 53 offers several policies:
- Latency-based: return the region with the lowest measured latency to the resolver.
- Geolocation: return a region based on the user's country or continent. This suits residency rules.
- Weighted: split traffic by percentage. This suits gradual rollouts and uneven capacity.
Here is a latency record with a health check. You would add a matching record for each other region.
resource "aws_route53_record" "api_us" {
zone_id = var.zone_id
name = "api.example.com"
type = "A"
ttl = 60
records = [var.us_endpoint_ip]
set_identifier = "us-east-1"
health_check_id = aws_route53_health_check.us.id
latency_routing_policy {
region = "us-east-1"
}
}DNS sees the user's resolver, not the user. If a user relies on a distant public resolver, latency routing picks the region closest to that resolver. EDNS Client Subnet reduces this problem but not every resolver sends it.
The TTL is your failover floor. A 60-second TTL means some clients keep the old answer for at least a minute. Some resolvers and applications cache for longer.
Anycast
With anycast, many locations advertise the same IP address through BGP (Border Gateway Protocol). The internet's routers send each packet toward the nearest advertising location, measured in network hops. If a location stops advertising, traffic shifts to the next nearest one. No DNS answer needs to expire.
Anycast gives fast failover and a single stable IP. The cost is control. "Nearest" means fewest network hops, which is not always lowest latency, and a routing change can move a user mid-connection. Long-lived TCP connections may reset when that happens.
Global load balancers
Services such as AWS Global Accelerator, Cloudflare, and Google Cloud's global external load balancer combine both ideas. They give you anycast IPs. The user's connection ends at a nearby edge location, and the edge proxies traffic over the provider's backbone to a healthy region. Failover is fast because the edge picks a backend per request or connection, with no DNS caching involved.
The trade-offs are an added hop, a dependency on the provider, and cost.
Choosing and common errors
- Use DNS routing when you want a simple setup and can accept failover of a minute or more.
- Use a global load balancer when you need fast failover or stable IPs for allowlists.
- Combine them: DNS geolocation selects a regional endpoint set, and each set sits behind its own accelerator.
Common mistakes:
- Setting a long TTL and then expecting fast failover.
- Testing latency routing only from your own network. Check from several locations.
- Routing a user to a different region on every request. If sessions or caches are regional, users see inconsistent state. Prefer sticky routing per user where the data design requires it.
Exercise
Your DNS record has a 300-second TTL and a region fails. A user's resolver cached the answer 10 seconds ago. What is the longest this user could keep reaching the failed region, and what change would shorten it without changing DNS?
Show answer
Up to about 290 more seconds, assuming the resolver honors the TTL. Putting a global load balancer or anycast front end in front of the regions removes the dependence on DNS caching, because the edge stops sending traffic to the failed region directly.