SysDesignPrep.com
Interactive concepts

DNS failover, TTLs and anycast when a region fails: an interactive simulator

When a whole region fails, traffic has to move to another one, and the slowest part is often not noticing the failure but getting clients to stop using the old address. DNS failover changes the answer, but every client and resolver that cached the old one keeps using it until the TTL expires, and some keep it longer. Anycast and global load balancers keep one address and move traffic behind it, so nothing cached goes stale.

The playground fails one of two regions at time zero and follows the next 20 minutes under four approaches. Then let a few resolvers ignore the TTL, as real ones do.

Region A fails at 0 s with half the clients on it, and health checks notice after 30 s. With a 5 minute TTL, cached answers keep sending clients to the dead region for up to 5 more minutes: 7.5% of all requests in these 20 minutes fail, and failures stay above 1% until 5.4 min in. A 30 s TTL cuts that to 1.9% but means 333K DNS queries a second from 10M clients instead of 33K. Returning both addresses turns failures into slow requests: a client that tries the dead region first waits out a 3 s connect timeout and then succeeds, 2.5% of requests in all. Anycast or a global load balancer switches behind one address, so only the 30 s before detection hurt: 1.3% failed. Here every resolver honours the TTL; real ones do not always.

DNS failover, 5 min TTLanswers cached up to 300 s
0%25%50%0 min5 min10 min15 min20 min
Requests failed
7.5%
Slowed by 3 s
0%
Below 1% after
5.4 min
DNS queries
33K/s
DNS failover, 30 s TTLanswers cached up to 30 s
0%25%50%0 min5 min10 min15 min20 min
Requests failed
1.9%
Slowed by 3 s
0%
Below 1% after
60 s
DNS queries
333K/s
Both addresses, client retriesTTL 60 s; 3 s connect timeout
0%25%50%0 min5 min10 min15 min20 min
Requests failed
0%
Slowed by 3 s
2.5%
Below 1% after
89 s
DNS queries
167K/s
Anycast or global load balancerone address; the switch is behind it
0%25%50%0 min5 min10 min15 min20 min
Requests failed
1.3%
Slowed by 3 s
0%
Below 1% after
30 s
DNS queries
3K/s
requests failingsucceeding after a timeouthealth checks notice

What each approach costs

  • DNS failover with a 5 minute TTL is cheap in DNS queries, but after the health checks flip the answer, cached copies keep half the clients on the dead region for up to 5 more minutes: 7.5% of all requests in the 20 minutes fail.
  • A 30 s TTL recovers within a minute, but 10 million clients now ask 333K times a second instead of 33K, and DNS lookups add latency to more requests.
  • Returning both addresses lets clients that support it try the second address when the first refuses. Nothing fails, but every client that picks the dead region first waits out a connect timeout, 2.5% of requests in this run.
  • Anycast or a global load balancer fails over in the time the health checks take, here 30 s, because the client’s address never changes. It is how CDNs and large cloud front doors work, and it needs a network that can announce one address from many places.
  • Resolvers that ignore TTLs are the long tail of every DNS approach: some ISPs, corporate resolvers and runtimes such as older JVMs cache answers for much longer. With 5% of clients behind them, even the 30 s TTL leaves 1.7% of requests failing ten minutes in.

The records

; DNS failover: health-checked answer, short TTL
api.example.com.  30  IN A  203.0.113.10   ; us-east, while healthy
api.example.com.  30  IN A  198.51.100.20  ; eu-west, the failover answer

; both addresses: clients try one, then the other on connect failure
api.example.com.  60  IN A  203.0.113.10
api.example.com.  60  IN A  198.51.100.20

; anycast: one address announced over BGP from every region;
; a region that fails withdraws its route or is drained by the global load balancer
api.example.com.  3600  IN A  192.0.2.1

In a system design interview

When a design runs in more than one region, say how users get moved off a failed one: “Users reach us through a global load balancer with an anycast address, which health-checks each region and drains a failed one within tens of seconds. We do not rely on DNS TTLs for failover, since some resolvers ignore them; DNS only picks the nearest edge. Clients retry idempotent requests once on connection failure.” Expect the follow-ups: how health checks avoid flapping, what happens to sessions and in-flight writes in the failed region, and whether the surviving region has the capacity for everyone.

Read the guide to global traffic management or what happens when you type a URL, see health checks and multi-region databases, or watch a strong candidate design Netflix.

Questions people ask

How does DNS failover work?

A DNS provider health-checks each endpoint and, when the primary fails, starts answering queries with the address of a healthy one. Clients only see the change once their cached answer expires, so failover takes the health check time plus up to one TTL, longer for resolvers that ignore the TTL.

What TTL should I use for DNS failover?

Short TTLs of 30 to 60 seconds make failover faster but multiply query volume and lookup latency; long TTLs of minutes to hours are cheap but slow to change. Many systems use short TTLs only on records that fail over and avoid relying on DNS for fast failover at all.

Do resolvers respect DNS TTLs?

Most do, but not all: some ISP and corporate resolvers enforce a minimum TTL, some clients and runtimes cache answers for longer than the TTL, and long-lived connections keep using an old address regardless. A share of traffic keeps reaching the old address well after the record changes.

What is anycast?

A routing technique where the same IP address is announced over BGP from many locations, and the network delivers each packet to the nearest one. If a location withdraws its announcement, traffic shifts to the next nearest within seconds, without any DNS change.

What is a global load balancer?

A load balancer reachable at one global address, often anycast, that health-checks backends in several regions and routes each request to a healthy, nearby one. Failover happens inside it, so clients never cache a stale answer.

Why return multiple IP addresses in DNS?

Clients that support it, such as browsers, try another address when a connection fails, so a dead endpoint costs a connection timeout rather than a failed request. It does not help clients that only use the first address, and the timeout still slows those requests.

How fast can a region failover be?

With anycast or a global load balancer, roughly the health check detection time, often 10 to 30 seconds. With DNS failover, detection plus the TTL plus the tail of resolvers that hold answers longer, often several minutes for a meaningful share of users.