Sub topic 14
Failback and restoring redundancy
Failover moves work off a failed component. The system is not safe yet. It is running on fewer copies than it was designed for, and one more fault may cause an outage. Failback is the work that follows: repairing or replacing the failed component, bringing it back in sync, and restoring the original level of redundancy.
This chapter assumes you know the failover sequence (detect, decide, switch, verify), the difference between synchronous and asynchronous replication, and the idea of fencing from earlier chapters.
Two goals: restore redundancy, restore placement
Failback combines two goals that are often confused.
- Restoring redundancy means the system again has the number of healthy copies it was designed for. This goal is always necessary.
- Restoring placement means moving the primary role back to the original node, zone, or region. This goal is often optional.
Suppose a database in zone A fails over to a replica in zone B. Once the zone A node is repaired and caught up, you have two healthy nodes. Redundancy is back. The primary is still in zone B. You can leave it there and treat zone A as the new standby, or you can move it back.
Leaving the primary in place is usually the safer choice. A role switch is another failover, with its own risk of errors and brief unavailability. Move the role back only when there is a reason, such as the following:
- The original site has more capacity, faster hardware, or lower latency to most clients.
- Cost, licensing, or data residency rules tie the primary role to a location.
- The new primary sits in a smaller or weaker environment that was meant for short use only.
Many teams treat nodes as interchangeable and never fail back. Others schedule the role switch in a planned maintenance window, not at the moment of repair.
The failback sequence
A safe failback follows a fixed order. Skipping steps is how a recovered component causes a second incident.
- Fix the cause. Find out why the component failed. Returning a node to service before you know the cause invites a repeat failure, sometimes a failure that loops.
- Keep the component out of service. The recovered node must not accept traffic or take the primary role on its own. Automatic restart scripts and orchestrators that bring it back as primary are a common source of split brain.
- Resynchronize the data. Bring the node's state up to date with the current primary.
- Verify health. Run health checks and real test requests against the node while it takes no production traffic.
- Reintroduce it gradually. Add it as a standby, or send it a small share of traffic, then raise the share.
- Switch roles only if needed. If you want the primary role back, do it as a planned, controlled failover.
- Confirm redundancy. Check that the system again tolerates the failure it was designed for.
Resynchronizing state
Stateless services need no resynchronization. You start a new instance, it passes health checks, and the load balancer begins sending it requests. State is where failback gets hard.
A returning data node is behind. While it was down, the new primary accepted writes. Worse, the old primary may hold writes that were never replicated to anyone. This depends on your replication mode.
- With synchronous replication, every acknowledged write exists on the standby. The old primary has nothing the new primary lacks, so it only needs to catch up.
- With asynchronous replication, the old primary may hold acknowledged writes the new primary never received. These writes are the data your RPO allowed you to lose. The histories have diverged.
Catching up
When the returning node's history is a strict prefix of the primary's history, it catches up by replaying the missing changes. This is the cheap case. It works if the primary still has the changes the node needs, for example in a write-ahead log (WAL) or replication log.
Logs are not kept forever. If the node was down longer than the log retention window, the primary has already discarded the missing entries. Then the node needs a full resynchronization, which copies the whole dataset from a snapshot or a base backup. This can take hours for a large database and adds load to the primary while it runs.
Plan for this. Know how long a full copy takes on your largest dataset, and set log retention so that a typical repair time fits inside it.
Diverged history
If the old primary accepted writes that the new primary never saw, you cannot just replay the new primary's log on top. The two copies have different histories. You have three options.
- Discard the divergent writes. Rewind or wipe the old primary and rebuild it from the new primary. This is the most common choice. It is simple and consistent, and the lost writes are the ones your RPO already accepted.
- Export and review the divergent writes. Before discarding them, copy them out so someone can inspect them and replay what matters. This suits financial or audit-sensitive data.
- Merge automatically. Some systems merge using conflict resolution rules such as last-writer-wins or CRDTs. This works only when the data model supports it. Last-writer-wins silently drops updates, so use it with care.
Whichever you choose, make it a deliberate decision made before an incident, not at 3 a.m. during one.
Avoiding failure loops
A node that fails, recovers, and fails again can cause more harm than a node that stays down. Each cycle triggers a failover, disrupts clients, and may corrupt state.
Three habits reduce this risk.
- Hold-down timers. Do not reinstate a node until it has passed health checks continuously for a set period, such as five minutes. Compare this with failure detection, which should react quickly. Detecting recovery should be slow, and detecting failure should be fast.
- Hysteresis. Use different thresholds for marking a node down and marking it up. A node may need three failed checks to be removed but ten consecutive passes to return.
- Manual or approval-based reinstatement. For critical stateful systems, require a person to confirm that the node is ready.
The NGINX settings from the traffic failover chapter show the same idea in a small form. max_fails=3 fail_timeout=10s removes a server after three failures, then retries it after 10 seconds. A very short fail_timeout makes a flapping server rejoin quickly, and every rejoin sends real requests to a node that may fail them again. Choose it with that in mind.
Reintroducing traffic gradually
Once a node is resynchronized and healthy, do not send it a full share of traffic at once. A cold node has empty caches, unwarmed connection pools, and possibly a cold JIT compiler or buffer pool. A sudden full load can make it slow or unstable, which causes a second failure.
Ramp up instead. Load balancers commonly support a slow-start setting that raises a server's weight over a period. You can also change weights by hand: 5%, then 25%, then 50%, then 100%, watching error rates and latency at each step.
Avoid failing back during peak load. A role switch causes a short interruption and a cold cache on the new primary. Do it at a quiet time, with the team watching.
Restoring redundancy before restoring the primary
The most important rule of failback is about order. After a failover, the system has no spare. If the only standby became the primary, there is now no standby. The next failure is an outage.
So the first priority after failover is to rebuild the missing copy, wherever it ends up. This is what "restoring redundancy" means in practice. Measure how long you run in this reduced state, because it is a period of elevated risk.
A simple way to reason about it is to reuse the availability formulas from the first chapter. A pair of 99% nodes in parallel gives about 99.99%. After one node fails, you have a single 99% node, which is the availability of a system with no redundancy. The longer the repair takes, the more of your time is spent in that weaker state.
def parallel(*availabilities):
all_down = 1.0
for a in availabilities:
all_down *= (1.0 - a)
return 1.0 - all_down
def degraded_risk(node_availability, repair_hours, hours_per_year=8760):
"""Expected outage hours per year caused by running with one
node while the other is being repaired, assuming one node
failure per year and independent failures."""
chance_second_fails = 1.0 - node_availability
# Rough estimate: probability the survivor is down during repair.
return chance_second_fails * repair_hours
print(parallel(0.99, 0.99)) # about 0.9999
print(degraded_risk(0.99, 4)) # 0.04 hours expected
print(degraded_risk(0.99, 48)) # 0.48 hours expectedThe estimate is crude, but it shows the direction. Repair time scales the exposure linearly. A 48-hour repair carries twelve times the exposure of a 4-hour repair. Faster replacement of a failed node, through automation, spare hardware, or cloud instances you can create on demand, improves availability directly.
This is why many teams prefer to replace a node over repairing it. In the cloud, you can launch a new instance from an image and let it replicate from the primary. This restores redundancy in minutes, and you can investigate the old node later.
Automate it, with limits
Failback steps are repetitive and easy to get wrong by hand. Automate the safe parts.
- Rebuilding a replica from a snapshot.
- Running health checks and the ramp-up schedule.
- Alerting when the system has run below full redundancy for longer than a threshold.
Keep a human in the loop for the risky parts, such as deciding which side wins after a diverged history, or switching the primary role for a critical database.
The alert on reduced redundancy is easy to forget and valuable. A system that quietly runs on one node for three weeks after a failover has no real redundancy, even though it looks healthy.
Common mistakes
| Mistake | Consequence | Fix |
|---|---|---|
| Recovered node starts as primary automatically | Split brain, diverged data | Start in standby or fenced state only |
| Failing back immediately after the fault clears | Repeat failure causes flapping | Use hold-down timers and hysteresis |
| Log retention shorter than repair time | Full resync needed, long window without redundancy | Size retention to repair time, or plan for fast rebuilds |
| Full traffic to a cold node | Slow responses, second failure | Slow start and gradual weights |
| Forgetting to rebuild the missing standby | Next failure is an outage | Alert on reduced redundancy |
| Failing back at peak load | Interruption when it hurts most | Schedule a quiet window |
| Untested failback procedure | Surprises during real recovery | Rehearse it in game days |
Failback deserves the same testing as failover. The next chapter covers drills, game days, and fault injection, and the failback path should be part of each one.
Exercise
A primary database in zone A failed and an asynchronous replica in zone B was promoted. Zone A is repaired two hours later. The old primary holds 40 seconds of acknowledged writes that never reached zone B. Describe the steps you take to restore redundancy, and say whether you must move the primary role back to zone A.
Show answer
Keep the zone A node out of service and fenced so it cannot accept writes. Decide what to do with the 40 seconds of divergent writes. Usually you export them for review if the data is sensitive, then discard them, since the RPO already accepted that loss. Rebuild the zone A node from the zone B primary, by a full resync if the log no longer covers the gap, or by log replay if it does. Verify health with checks and test requests, then add it as a standby and confirm replication lag is low. Redundancy is now restored. You do not have to move the primary role back. Do that only if zone A has a real advantage such as lower latency or more capacity, and then do it as a planned role switch during a quiet period.
Exercise
A load balancer removes a server after 3 failed health checks and returns it after 1 passing check. A server with a memory leak crashes every few minutes. Explain what happens to users and give two changes that help.
Show answer
The server keeps getting removed and returned. Each time it returns after one passing check, it receives real traffic and fails again, so users see repeated errors even though the system keeps "recovering". Two changes help: require several consecutive passing checks before reinstatement (hysteresis), and add a hold-down timer or slow start so the server must stay healthy for a period and ramps up gradually. Fixing the memory leak and keeping the server out until then is the real cure.