Active-passive and active-active
Waiting, or working
Section titled “Waiting, or working”With two or more regions, the first question is who serves the users. There are two answers.
In an active-passive layout, one region, the primary, serves everyone, and another, the standby, waits. AWS’s disaster-recovery whitepaper describes it that way: the active site hosts the workload and serves traffic, and the passive site does not serve traffic until a failover is triggered. Amazon Route 53 has a routing policy for exactly this: it answers with the primary while the primary is healthy, and with the secondary when it is not.
In an active-active layout, every region serves traffic. The whitepaper’s wording for its most demanding option is that it serves traffic from all the regions to which it is deployed. Users are sent to the region that suits them, normally the nearest.
The whitepaper also names degrees of waiting. A pilot light has the data replicated and the core infrastructure in place, but the application servers are switched off, and it cannot process requests until someone turns them on. A warm standby is a scaled-down but fully functional copy that can take traffic at once, at reduced capacity. A hot standby is sized to carry the full load and serves nothing until needed. The lab’s standby is the last of these, with a promotion delay: full size, idle, ready to be told to take over.
Mental model. In active-passive, the second region is insurance you pay for every month and use rarely. In active-active, the second region does useful work all the time, and the insurance is a margin you keep in every region.
Try it: who carries what
Section titled “Try it: who carries what”The lab starts with three regions, Active-active, 1,200 requests a second at the peak, and 8 servers in each region that each serve 100 requests a second, so each region can serve 800. Users go to the nearest region, which gives the loads in the table of regions: 480 requests a second in North America, 420 in Europe and 300 in Asia-Pacific. All three are under 800. Nothing is wrong in normal running.
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.
Read Each region must carry. It says 900 requests a second, 75% of the peak, and that each region can serve 800. That is what the busiest region left would have to carry after the worst single loss, and the table of losses shows where it comes from.
- If North America is lost, its users go to the nearest region left, which is Europe: 80 ms away, against 160 ms for Asia-Pacific. Europe then carries
420 + 480, which is 900 requests a second, 113% of what it can serve. 100 requests a second do not fit. - If Europe is lost, North America takes its users and carries 900, also 113%.
- If Asia-Pacific is lost, its users also go to North America, which carries
480 + 300, which is 780, or 98%. That fits.
The lab says so below the figures: not big enough, because if the wrong region is lost, up to 100 requests a second would be refused. A layout is only as good as its worst loss.
How much capacity is enough?
Section titled “How much capacity is enough?”If the load could be spread perfectly evenly over the regions left after a loss, each of N regions would have to carry the peak divided by N − 1. For three regions that is 1200 / 2, which is 600 requests a second, 50% of the peak. The lab prints the same sentence: spread evenly, three regions need at least 1/2 of the peak each, which is 600, and at that size each region runs at 67% in normal times. For two regions, the figure is 1200 / 1, the whole peak, and each region runs at 50% in normal times: with two regions, each has to be able to carry everything.
Nearest-region routing is not even. Europe and North America take in the users of a lost neighbour, and the neighbour’s users do not split. That is why the lab needs 900 and not 600: the busiest region left carries 75% of the peak and not 50%. Raise Servers in each region and watch it change.
- With 9 servers, each region can serve 900. The worst loss now takes the busiest region to exactly 100% of its capacity. The lab says every region is big enough for the worst single loss.
- With 10 servers, each region can serve 1,000, and the worst loss leaves the busiest region at 90%. That margin is the difference between a region that fits exactly and one that has room to absorb a spike.
Count what that costs. The peak needs 1200 / 100, which is 12 servers’ worth of work. The layout that survives any loss with three active regions uses 3 × 9, which is 27 servers at the tightest fit, and 3 × 10, which is 30, with a margin. The insurance is real, and it is paid for in servers that are mostly idle until the day they are needed.
Now choose Active-passive. Everyone is served by North America, so Mean round trip, user to region goes back to the single-region 76 ms: the standby does not make anyone faster. Each region must carry now says 1,200, the whole peak, and with 8 servers the primary is overloaded even in normal running: 1,200 against 800, which is 150%. An active-passive layout is sized for the entire peak in one region, and in the standby too. Raise Servers in each region to 12 and the layout fits, at 100%. With two regions that is 2 × 12, which is 24 servers, one of them idle; three active-active regions at the tightest fit use 27, and none of them is idle.
So neither layout is cheaper by nature. In these numbers the two-region active-passive layout uses 24 servers and the three-region active-active layout 27, or 30 with a margin, and the first gives every user the latency of one place. What the extra servers buy is a nearby region for every user and no idle region. What they cost is that every region now takes writes, which the next lesson is about.
Two ways to use a region: sort the statements
Section titled “Two ways to use a region: sort the statements”Challenge
Active-passive or active-active?
In an active-passive layout one region serves everyone and the others wait. In an active-active layout every region serves the users nearest to it. Put each statement under the layout it describes.
Sorting needs JavaScript.
Categories
- Active-passive
- One primary serves; a standby waits to take over.
- Active-active
- Every region serves users and takes writes.
Check your answers at least once before looking at the answers.
What happens if the regions are sized only for normal traffic?
Section titled “What happens if the regions are sized only for normal traffic?”This is the most common mistake, and the lab starts with it. With 8 servers per region, every region is well under its capacity in normal running, 480 against 800 at the busiest. Nothing looks wrong until a region is lost, and then the nearest region has to take on more than it was ever sized for.
Amazon’s Route 53 guide gives the same warning for its weighted failover: if the last healthy resource cannot handle all the traffic when the others are unavailable, the application becomes unreliable. The failure is not at the moment of the loss, it is at the moment of the next demand. A region that fits a normal day at 60% can be pushed past its limit by one failure. The lesson on availability asked the same question of instances inside one region, and the answer is the same: spare capacity is part of the design.
The lesson on failing a region shows what happens to the 100 requests a second that do not fit.
- Active-passive: one region serves everyone and another waits. Active-active: every region serves the users nearest to it.
- In the lab, active-active gives 20 ms and active-passive 76 ms, because the standby serves nobody.
- Spread evenly, N regions each need the peak divided by N − 1: 600 requests a second for three regions, and the whole peak for two. Nearest-region routing is not even, and the busiest region left needs 900, 75% of the peak.
- With 8 servers a region cannot take that: 100 requests a second would be refused. 9 servers fit exactly, and 10 leave the busiest region at 90%.
- An active-passive layout is sized for the whole peak: 12 servers per region in the lab. Neither layout is free, and neither is automatically cheaper.
Next: replication and write conflicts, once two regions both hold the data.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.