Networking
DNS traffic steering and anycast
How DNS answers can route users by weight, location, latency or health, and how anycast sends the same IP address to the nearest of many servers.
DNS can do more than return one fixed address. The authoritative server can choose the answer for each lookup, based on who is asking, how healthy each target is, or how the traffic should be split. This is traffic steering. It is cheap, global and coarse: the answer is cached by resolvers, so routing changes lag behind.
Anycast works at a different layer. It doesn't change the DNS answer. It announces one IP address from many places on the internet, so routing sends each user's packets to the nearest location.
Routing policies
The DNS provider picks an answer according to a policy:
| Policy | Chooses by | Typical use |
|---|---|---|
| Weighted | Fixed percentages | Gradual rollouts, such as 5% to a new version |
| Geolocation | The resolver's or client's region | Data residency, region-specific content |
| Latency | Measured latency from a region | Sending users to the fastest region |
| Failover | Health check status | Primary and backup sites |
| Multivalue | Several healthy answers, returned in random order | Simple client-side spreading |
Two details matter. Geolocation usually sees the resolver's address, not the user's. A user on a public resolver far from home may be routed by the resolver's location. Also, every policy is subject to caching: the TTL decides how fast a weight or failover change reaches users, so a failover set at 300 seconds takes at least that long to act.
Health checks are the part that makes failover real. The provider must probe the target, and it should drop an unhealthy answer quickly. Check that the health check tests the service, not just whether a port answers.
Anycast
With anycast, the same IP range is announced from many data centers. Routers use BGP to send each packet along the shortest path to whichever location they reach. The user doesn't choose; the network does.
Anycast suits stateless, short-lived traffic such as DNS resolvers, CDN edges and DDoS absorption. Spreading attack traffic across many sites limits the damage to any one of them. The drawback is less control. You can't easily pin a user to a site, and a routing change can move a user's traffic mid-session.
That is why anycast is often combined with TCP-based protocols carefully. A route flip can break a long connection, so keep sessions short or stateless at the edge.
Where steering stops
DNS steering works at the granularity of a name. It can't split traffic within one connection, and it can't react in seconds. For fast failover between servers in a region, a load balancer with health checks is the right tool. DNS sends users to the right region, and the load balancer picks the server.
Warning
Failover by DNS alone is slow. Plan for the TTL plus resolver caching, which is often minutes, not seconds.
Common mistakes
- Expecting a failover to take effect in seconds when the TTL is 300 or more.
- Using geolocation to enforce legal boundaries, when resolvers may be far from users.
- Running anycast for a service that holds long TCP sessions, then being surprised by mid-session route changes.
Check yourself
- Why does a 300-second failover take minutes to protect users, not 300 seconds? Answer: after the health check fails, resolvers still hold the old answer until their cached copy expires, and some enforce longer minimums.
- How does anycast send users to different sites with one IP address? Answer: routers use BGP to announce the same prefix from many places, so each packet follows the shortest route to a nearby site.
Key takeaways
- DNS steering chooses answers by policy: weight, location, latency, health or random spread.
- Anycast sends one IP address to the nearest site through BGP routing.
- DNS steering is coarse and cached. Use load balancers for fast, per-request failover.
Further learning
Next, see DNS outages and ndots for how DNS failures spread across services.
Related
DNS
How names become addresses, which record types matter, how caching and TTLs shape change speed, and why DNS failures look like outages of everything else.
Load balancers, DNS and the edge in the cloud
Configuring the traffic layer, from DNS and cloud load balancers through TLS, WAF and CDN to a regional traffic shift. Start here for the map of edge pages.
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.
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.