Global traffic routing: GeoDNS and anycast
Two jobs for the router
Section titled “Two jobs for the router”With more than one region, a router at the front has two jobs. In normal running it sends each user to a good region. When a region is lost, it has to stop sending users there, and send them to a region that is left. The lab’s diagram calls it global routing. In practice it is one of two things, or both: DNS that gives different answers, or an address that the network delivers to the nearest site.
The lesson on CDNs told them apart for edge sites: DNS steering, anycast, and a load balancer inside a site. The same tools choose between regions.
GeoDNS: the answer depends on who asks
Section titled “GeoDNS: the answer depends on who asks”GeoDNS is the name for DNS that answers according to where the question comes from. Amazon Route 53, for example, offers several routing policies for a record: geolocation, which routes by the location of the users; geoproximity, by the location of the resources; latency, to the region with the best latency; failover, for an active-passive pair; weighted, in proportions you choose.
The catch is in the word asks. The authoritative server does not see the user. It sees the recursive resolver that asks for the user, and RFC 7871 states the problem plainly: since most queries come from intermediate recursive resolvers, the source address is that of the resolver and not of the query originator. Route 53 says that, without more, it uses the resolver’s address to guess where the user is. A user whose resolver is far away, such as a public resolver run from another country, can be sent to the region that suits the resolver. The fix is the EDNS client-subnet extension, with which the resolver passes a shortened version of the user’s address. RFC 7871 recommends truncating to 24 bits for IPv4 and 56 for IPv6, and notes a privacy cost: it recommends that the feature be off by default in name server software, enabled only where the benefit is clear.
Even the location is not always the best guide. Route 53’s latency-based routing uses measurements of latency between users and its data centres, not distances, and says that latency changes with the network: a request routed to one region this week might go to another next week. The lab’s table of round trips is fixed, which is a simplification.
Anycast: the network chooses
Section titled “Anycast: the network chooses”With anycast, the same address is available in several places, and the network delivers each packet to one of them. RFC 4786 defines it as making a service address available in multiple, discrete locations, with datagrams routed to one of them. A region is taken out by withdrawing its route: availability of the service triggers the advertisement and its absence triggers a withdrawal.
AWS offers it as a service for regions. With AWS Global Accelerator, several endpoints in one or more regions share the same static addresses, health checks route traffic to the healthy ones, and, as the AWS whitepaper notes, this avoids the caching problems that can occur with DNS. Anycast moves traffic when routing changes, not when a cache entry expires.
It has its own hazard. RFC 4786 says that the routing system’s choice of node ought to be stable for substantially longer than the expected transaction, and warns that long-running flows have failure modes more complex than a simple destination unreachable. That is why anycast fits short exchanges best, as the CDN lesson put it, and why a long connection that is moved mid-way can break.
Mental model. GeoDNS decides when the name is looked up, and a cache holds the decision for the TTL. Anycast decides at every packet, and the routing table holds the decision. One is slow to change and easy to see; the other is fast to change and harder to see.
Try it: noticing a failure and moving the users
Section titled “Try it: noticing a failure and moving the users”The lab models the DNS side. Under Fail a region choose North America. Read Average time to serve again: 60 s, and under it, between 30 s and 90 s. The numbered steps below the figures give the arithmetic.
Users in North America, Europe and Asia-Pacific reach a service that runs in one, two or three regions. Choose active-passive or active-active, fail a region, and see where its users go, whether the regions left can hold them, how long the switch takes, and what data was not yet copied out. The numbers come from a model with illustrative inputs.
Regions: latency, failover and data at risk
Every number here is model output. The round-trip times, the traffic from each continent and the lag are illustrative inputs, not measurements of any provider.
A write is confirmed first and copied afterwards, so the copy trails by the lag.
- Mean round trip, user to region
- 20 msWith one region: 76 ms
- Each region must carry
- 900 req/s75% of the peak; each region can serve 800 req/s
- Average time to serve again
- —Fail a region to see it
- Data at risk (RPO)
- 2 s of writesThe latest writes, if their region fails
- With 3 regions, users are on average 20 ms from the region that serves them, and the worst-placed group 20 ms. With a single region (the best placed: North America) it would be 76 ms on average and 160 ms for the worst group.
- A region has 8 servers and can serve 800 requests a second. If one region is lost, the busiest region left would have to carry 900 requests a second, 75% of the 1,200 peak.
- Spread evenly, 3 regions need each at least 1/2 of the peak, 50%, which is 600 requests a second. At that size each region runs at 67% in normal times.
- Not big enough: if the wrong region is lost, up to 100 requests a second would not fit and would be refused.
- Replication is asynchronous with a lag of 2 s: the latest 2 s of writes exist only in the region that accepted them.
- Two regions accept writes, so two users can change the same record before either region has heard of the other's change: that is a write conflict.
| User group | Share of requests | Served by | Round trip | One region (North America) |
|---|---|---|---|---|
| Users in North America | 40% | North America | 20 ms | 20 ms |
| Users in Europe | 35% | Europe | 20 ms | 80 ms |
| Users in Asia-Pacific | 25% | Asia-Pacific | 20 ms | 160 ms |
| Mean over all users | 20 ms | 76 ms |
| Region | Load before | Load after | Capacity | Utilisation | State | Writes not yet copied out |
|---|---|---|---|---|---|---|
| North America | 480 req/s | 480 req/s | 800 req/s | 60% | Busy | 96 |
| Europe | 420 req/s | 420 req/s | 800 req/s | 53% | Busy | 84 |
| Asia-Pacific | 300 req/s | 300 req/s | 800 req/s | 38% | Healthy | 60 |
| Region lost | Busiest region left | Utilisation | Does not fit | State |
|---|---|---|---|---|
| North America | 900 req/s | 113% | 100 req/s | Overloaded |
| Europe | 900 req/s | 113% | 100 req/s | Overloaded |
| Asia-Pacific | 780 req/s | 98% | 0 | Saturated |
Users go to the nearest region that is left (active-passive: to the standby). Spread perfectly evenly, the load on each region left would be the peak divided by N − 1, where N is the number of regions. Nearest-region routing is rarely even, so the busiest region carries more.
| Record | Before | Written in North America | Written in Europe | Last-write-wins keeps | A merge keeps |
|---|---|---|---|---|---|
| Customer's first name | Ana | Anne | Anna | Anna · loses the write from North America | Anne / Anna · both versions, for a person to choose |
| Likes counter | 10 | 11 | 11 | 11 · loses the write from North America | 12 · both increments |
| Shopping cart | (empty) | book | lamp | lamp · loses the write from North America | book, lamp · both items |
Last-write-wins compares timestamps taken from each region's clock. If the second region's clock is behind, its later write can look older and lose. A merge rule, such as a conflict-free replicated data type (CRDT), combines the writes instead of dropping one. It suits a counter or a set; for a field like a name nobody can say which value is right, so the versions are kept for a person to choose.
Illustrative values, not benchmarks of any real product.
Model notes
Assumptions
- Users are in three places and send a fixed share of the requests: 40% from North America, 35% from Europe and 25% from Asia-Pacific. Two regions are in North America and Europe; the third is in Asia-Pacific. Every round-trip time in the lab (20 ms to the region on the same continent, 80 to 200 ms between continents) is an illustrative input, not a measurement.
- Every region has the same servers, and each server can serve 100 requests a second. A region is overloaded when it carries more than it can serve. The lab does not model the slowdown that comes before that.
- A health check runs on a fixed interval, and traffic is moved after the chosen number of failed checks in a row. The time shown is the longest this takes. A resolver keeps the answer it was given for up to the TTL, so the time left on a cached answer is spread evenly between zero and the TTL.
- Replication is to one other region. Asynchronous: a write is confirmed before it is copied, and the copy trails by the lag you set. Synchronous: a write waits for the nearest other region to confirm.
Simplifications
- Round-trip time stands in for latency. It leaves out the time a server needs, the number of round trips a request makes (name lookup, connection, TLS, the request itself), and congestion.
- Users go to the region with the lowest round trip in the table. Geographic DNS, anycast or a global load balancer decide by the network and not by the map, and may differ.
- After a failure every request to the failed region fails until its client has moved. There are no retries, and every client honours the TTL. Some resolvers and clients keep an answer longer than the TTL, and the model does not.
- The standby in active-passive mode is idle until it is told to take over. It then needs the promotion time you set and serves at once at full capacity. A cold standby that must also start servers takes longer, and is not modelled.
- The lab loses a whole region. A part of a region (one zone, one service) fails more often and in other ways, and a region can be reachable and still too slow.
- Data at risk is the writes a second that the failed region was accepting, times the lag. The writes that were not copied are stranded in the failed region, not necessarily destroyed: they come back if the region does. A real lag moves around and grows under load.
- The write conflicts are three illustrative records, written in two regions 0.2 seconds apart, before either write reaches the other region. How often real conflicts happen depends on the data, which the model does not have.
- Synchronous replication is modelled as a wait for the nearest other region. Protocols that agree on every write between regions (consensus) cost more round trips and are not modelled, nor is what happens to a write when the other region cannot be reached: it waits, or it is refused.
Parameter values are illustrative. They are not benchmarks of any real product.
- The health check runs every 10 s (Health-check interval), and traffic is moved after 3 failed checks in a row (Failed checks before failover). Detection takes
10 × 3, which is 30 s. Route 53’s checks run at an interval of 10 s or 30 s, and the threshold is the number of consecutive failures you set. - The record then has a new answer, and the old answer is still in caches. A resolver may keep it for the DNS time to live (TTL), 60 s. A client whose entry has just expired is served again at 30 s: the fastest. A client that was given the answer just before the move holds it for the full TTL, and is served again at
30 + 60, which is 90 s: the slowest. - The time left on the cached answers is spread evenly from zero to the TTL, so on average a client waits half of it. The average is
30 + 60 / 2, which is 60 s. - Meanwhile every request to the failed region fails. 480 requests a second were going to North America, so about
480 × 60, which is 28,800 requests fail for the average client.
Move the sliders and read the three times again. A TTL of 5 s gives 30 s at the fastest, 35 s at the slowest and 33 s on average (the lab rounds 32.5). A TTL of 300 s gives 30 s, 330 s and 180 s: the cache, not the check, now decides how long users are stranded. With a check every 5 s, 2 failures and a TTL of 20 s, the fastest is 10 s, the average 20 s and the slowest 30 s. The lesson on DNS said that lowering a TTL does not help at once, because the old long TTL has to run out first. The lesson here is the opposite side of the same fact: lower it before you need it.
The lab assumes that every client honours the TTL. Real clients and resolvers do not all behave alike. RFC 8767 describes one case on purpose: a resolver that cannot refresh an expired record may keep using it, and the RFC suggests keeping it for between 1 and 3 days at most. The model does not include any case where an answer outlives its TTL.
What happens if the check is faster and wrong?
Section titled “What happens if the check is faster and wrong?”Shorter is not safer. Set Health-check interval to 1 s, Failed checks before failover to 1 and DNS time to live (TTL) to 5 s. The fastest time is 1 s, the average 3.5 s and the slowest 6 s. The lab shows the best case and not the cost: a check that fails once triggers a failover, and a failover triggered by a blip is a failure of your own making.
Route 53 shows how a provider guards against it: its health checkers sit in many places around the world, and an endpoint counts as healthy if more than 18% of them say it is, so that a network problem isolating one location does not take a region out. AWS’s whitepaper goes further and warns that failover started automatically by health checks or alarms should be used with caution, because recovery time and recovery point will be greater than zero, and a failover on a false alarm incurs those losses for nothing. Manually started failover is therefore often used, with the steps automated so that starting it is like pressing a button. The lesson on health checks made the same trade between speed and false alarms for servers behind one balancer.
What happens if the TTL is long?
Section titled “What happens if the TTL is long?”Then the cache decides. With a TTL of 300 s, 330 s is the slowest and 180 s the average, and about 480 × 180, which is 86,400 requests, fail for the average client. A long TTL saves lookups and makes a failover slow, and the way out is not to guess when you will need it. Choose a TTL for the failover time you can accept, or move the decision off DNS with anycast.
- GeoDNS answers by location, and sees the resolver and not the user unless the client-subnet extension passes part of the user’s address. Latency-based routing uses measured latency, which changes.
- Anycast delivers each packet to a nearby site and withdraws a failed site’s route. It does not wait for a TTL, and it suits short exchanges best.
- The time to move users is the check interval times the failures, plus the wait for cached answers: 30 s, then 0 to 60 s, so 30 s at the fastest, 60 s on average and 90 s at the slowest. About 28,800 requests fail for the average client.
- A TTL of 300 s makes the average 180 s and the slowest 330 s; a TTL of 5 s gives 33 s and 35 s.
- A faster check is not free: a failover on a false alarm costs what a real one does, so providers check from many places and often leave the decision to a person.
Next: what a regional failure does to capacity and data, and how to evacuate a region.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.