Sub topic 7
The failover sequence: detect, decide, switch, verify
This chapter assumes you know what active-passive and active-active designs are, and that you have seen health checks and heartbeats. It covers what happens between "a component stopped working" and "users are served again."
The four steps
Failover is the process of moving work from a failed component to a healthy one. Every failover, manual or automatic, follows the same four steps.
- Detect. Something notices the component is unhealthy, usually through failed health checks or missed heartbeats.
- Decide. Something chooses to act and picks the replacement. This may be a person, a script, or a cluster manager.
- Switch. Traffic, a virtual IP, or the primary role moves to the replacement.
- Verify. Something confirms the replacement is actually serving correct results.
Each step takes time. Your total outage is roughly the sum: detection time, plus decision time, plus switch time, plus verification time. This sum is the main contributor to your recovery time objective (RTO), which a later chapter covers.
Detect
Detection is a trade-off. If a check runs every 5 seconds and you require 3 failures in a row, a hard failure takes up to 15 seconds to confirm. Shorter settings find failures faster but raise false positives: a brief garbage-collection pause or a dropped packet triggers a failover that was not needed. An unnecessary failover is not free, because it can cause a short outage of its own.
Decide
Automatic decisions are fast but can be wrong. Manual decisions are slower but handle ambiguous cases. A common compromise is to automate failover for stateless tiers and require a human or a quorum vote for databases, where a wrong switch can lose or corrupt data.
The decision step must also answer two questions:
- Is there a healthy replacement? Failing over to a standby that is behind on replication or also unhealthy makes things worse.
- Is the old component really out of service? If not, you risk two active primaries, which the split brain chapter covers.
Switch
Switching means redirecting work. The common mechanisms are:
| Mechanism | What changes | Typical delay |
|---|---|---|
| Load balancer removes a server | Pool membership | Seconds |
| Virtual IP moves to standby | Which host answers the address | Seconds |
| DNS record updated | Name to address mapping | Up to the record's TTL, and longer if clients cache |
| Database replica promoted | Which node accepts writes | Seconds to minutes |
Verify
Many failover plans stop at "traffic moved." Verification checks the result. Good checks go beyond "the port is open":
- Run a real request through the full path, such as a login or a read-after-write.
- Confirm the new primary has the expected data and is not serving stale state.
- Confirm the old primary is no longer accepting writes.
- Confirm remaining capacity can carry the load. A failover from two servers to one may succeed and then overload the survivor.
Common errors
- Flapping. A component alternates between healthy and unhealthy, and the system keeps failing over and back. Add a minimum time between failovers and require several consecutive successes before marking a component healthy again.
- Failing over into a cold standby. The standby has empty caches or no warm connections, so it is technically up but too slow. Warm it, or expect a slow period after the switch.
- Skipping verification. The system reports success while users still see errors.
- Untested decision logic. The script that chooses the replacement has never run against a real failure.
Putting numbers on it
Suppose checks run every 5 seconds with 3 failures required, the load balancer switches instantly, and verification takes 10 seconds. The worst case is about 15 seconds of detection plus 10 seconds of verification, so 25 seconds. Cutting the interval to 2 seconds with 3 failures gives 6 seconds of detection, but with a higher chance of false failovers.
Exercise
A database primary fails. Health checks run every 3 seconds and require 4 consecutive failures. An operator takes about 60 seconds to approve promotion, and the promotion itself takes 20 seconds. Ignoring verification, what is the worst-case time from failure to the new primary accepting writes, and which step dominates?
Show answer
Detection takes up to 3 x 4 = 12 seconds. Adding 60 seconds for the decision and 20 seconds for the switch gives 92 seconds. The decision step (human approval) dominates. Automating it would reduce the time but increases the risk of a wrong promotion, so a quorum-based or carefully tested automatic decision is the usual middle ground.