Failover
Replace what failed
Section titled “Replace what failed”The protections so far make a failing dependency less harmful: a retry hides a blip, a breaker stops the calls, a bulkhead confines the damage. None of them makes the dependency work. Failover does: when a component is lost, another one takes its work. It has three parts. The failure has to be noticed, the work has to be switched to the other copy, and the redundancy has to be restored afterwards, because after a failover the system has one copy fewer.
The database case has its own lesson, failover and lost writes, where a replica is promoted to primary and the writes it never received are lost. This lesson is about the general shape, which covers a stateless service behind a load balancer as well as a database.
Text version of the diagram
- Clients (outside Replica servers) sends requests to API.
- API (outside Replica servers) sends requests to Primary, Replicas.
- Primary (outside Replica servers) sends requests to Replication.
- Replicas (inside Replica servers) does not call another component.
- Replication (inside Replica servers) does not call another component.
In the picture, three API instances share the requests, one primary takes the writes and two replicas answer the reads. Each of those is a copy of something that can be lost, and each has a different kind of failover: an API instance can simply be dropped from the rotation, a replica too, while a primary needs a replica promoted.
Active-passive and active-active
Section titled “Active-passive and active-active”Amazon’s Route 53 documentation gives the two shapes names. In active-passive failover, a primary resource is available most of the time and a secondary is on standby: when responding to queries, Route 53 includes only the healthy primary resources, and begins to include the secondary only if all the primaries are unhealthy. In active-active failover, all the resources are available most of the time, and when one becomes unavailable Route 53 detects that it is unhealthy and stops including it. The multi-region module takes the same two shapes to whole regions.
Active-active does not need to wait for a decision: the others are already working. Active-passive keeps a standby that takes no traffic until it is needed.
The detection delay
Section titled “The detection delay”Nothing switches until the failure is noticed, and a health check notices it late. The health checks lesson works out the delay: with a probe every i seconds and f failures in a row, the server is taken out more than (f − 1) × i and at most f × i seconds after it fails. Take two servers that share 100 requests a second, and a check every 10 s with 3 failures. The server is out of rotation after more than 20 s and at most 30 s. The dead server is sent 50 requests a second, so in the worst case 50 × 30, which is 1,500 requests fail. With a check every 2 s and 3 failures, as in HAProxy’s defaults, the worst case is 6 s and 50 × 6, which is 300.
A retry covers the gap. Under round robin the next request goes to the other server, so a retried request lands on the live one, and the user sees a slower answer, not an error. That is why retries and failover belong together, and also why the retried request must be safe to repeat.
Mental model. Failover is a decision made on old information. It starts late, because the failure is noticed late, and it costs what was in flight when the component was lost.
The survivors must carry the load
Section titled “The survivors must carry the load”Two servers that each run at 60% utilisation look comfortable. When one fails, the other must take both loads: 2 × 60%, which is 120%. It cannot, and the failover that was meant to save the service overloads the one server left. Route 53’s documentation has the same warning for weighted records: all the records with nonzero weights must be unhealthy before it begins to respond with the zero-weighted ones, which can make a site unreliable if the last healthy resource cannot handle all the traffic. To survive the loss of one of n servers, each must run below (n − 1) / n of its capacity: below 50% for two, below about 67% for three. The health checks lesson asks the same question of a load balancer.
When the decision is wrong
Section titled “When the decision is wrong”A failover can also be a mistake. A health check can fail for a reason that has nothing to do with the server, and moving the traffic away from a server that was fine, or promoting a replica while the primary is alive, causes the outage that it was meant to avoid. Route 53 treats this seriously: when all the records of a group are considered unhealthy, it reverts to considering all of them healthy, so that a misconfigured check cannot leave a name with no answer. It also notes that during an internet partition different health checkers may reach different conclusions about the same endpoint.
For state, a wrong decision is worse. The PostgreSQL documentation says that if the old primary comes back, there must be a mechanism to tell it that it is no longer the primary, which it calls STONITH, shoot the other node in the head, to avoid both systems thinking they are the primary, which leads to confusion and in the end data loss. The split brain lesson is about that case. The same page says that after a failover only one server is left, a degenerate state, and a standby must be recreated before the system is redundant again. PostgreSQL itself does not provide the software to identify the failure on the primary, so one has to be added.
Choosing between the four
Section titled “Choosing between the four”The module’s four protections answer four different failures. Sort the situations below under the protection that answers each one.
Challenge
Which protection fits?
Four protections answer four different failures. A retry hides a brief failure. A circuit breaker stops calls to a dependency that is down. A bulkhead keeps one dependency from using up what the others need. A failover moves the work to a standby. Put each situation under the protection that answers it.
Sorting needs JavaScript.
Categories
- Retry with backoff and jitter
- Try the same call again, after a wait.
- Circuit breaker
- Stop calling a dependency that keeps failing, and test it now and then.
- Bulkhead
- Give each dependency or client its own share of the resources.
- Failover
- Send the work to a standby or to another copy.
Check your answers at least once before looking at the answers.
What happens if the standby has never been used?
Section titled “What happens if the standby has never been used?”A standby that has never taken traffic is a standby whose configuration, capacity and data nobody has checked. The first time the decision is made may be during a real failure. A failover that is rehearsed is a failover that works when needed, and a rehearsal is also a chance to measure the detection time and the load on the survivors, the two numbers in this lesson. The failure engineering module is about doing this on purpose.
- Failover has three parts: notice the failure, switch the work, and restore the redundancy. After it, there is one copy fewer.
- Active-passive keeps a standby that takes over when all the primaries are unhealthy. Active-active keeps every copy at work and stops using the one that is unhealthy.
- A check every 10 s with 3 failures takes a server out after more than 20 s and at most 30 s. At 50 requests a second for the dead server that is up to 1,500 failed requests, and 300 with a 2 s check.
- Two servers at 60% become one at 120%: for the loss of one of
nservers, each must stay below(n − 1) / n. - A wrong failover is an outage of its own, and for state it can mean two primaries. Rehearse the switch.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.