In a cricket match, if a fielder gets injured, a substitute runs on and the game continues. The crowd may barely notice. The team planned for this: a substitute was already padded up and waiting.
Software needs the same plan. Servers crash, disks fail, power goes out, whole data centres lose their network. Failover is the plan for what happens next. This guide explains what failover is, how a system knows when to fail over, and why doing it well is harder than it sounds.
What is failover?
Failover is switching work from a part that has failed to a backup that can take its place, ideally automatically and quickly enough that users don’t notice much.
Failover exists to remove single points of failure. A single point of failure (SPOF) is any part whose failure brings the whole system down. One database server with no copy is the classic example: if it dies, nothing works. Add a standby copy and a way to switch to it, and that SPOF is gone.
The steps are always the same:
- Detect that something has failed.
- Decide to switch (and make sure only one switch happens).
- Switch traffic to the backup.
- Recover: repair or replace the failed part, so you have a backup again.
How does a system know something failed?
The usual tool is a health check or heartbeat. Every few seconds, a monitor asks each server “are you OK?”, or each server says “I’m alive” to the others. If a server misses several checks in a row, it is treated as dead.
The hard part is choosing how fast to decide:
- Too eager: a server that was just slow for two seconds gets declared dead, and you fail over for nothing. Unneeded failovers cause their own outages.
- Too patient: a dead server stays “alive” for a minute while users get errors.
Most systems wait for a few missed checks in a row, which takes seconds to tens of seconds. That delay, plus the time to switch, is your failover time.
Active-passive vs active-active
There are two common setups.
Active-passive (also called primary-standby). One server does all the work. A second one sits ready, kept up to date with a copy of the data, but takes no traffic. When the primary fails, the standby is promoted and becomes the new primary. Most relational databases are run this way, using replication to keep the standby current.
- Simple to reason about: only one place accepts writes at a time.
- You pay for a machine that sits mostly idle.
- Switching takes some time, often seconds to a minute or more.
Active-active. Two or more servers all handle traffic at the same time, usually behind a load balancer. If one fails, the load balancer stops sending it requests and the others carry on.
- No idle machines, and switching is nearly instant for stateless servers.
- Each survivor must have spare capacity to absorb the failed one’s share. Two servers each at 80% load can’t cover for each other.
- For databases, letting two places accept writes at once is hard, because the copies can disagree.
| Active-passive | Active-active | |
|---|---|---|
| Who serves traffic | One at a time | All of them |
| Idle cost | A standby doing little | None, but you need headroom |
| Switch time | Seconds to minutes | Near instant for stateless servers |
| Typical use | Databases, single-writer systems | Web and app servers, multi-region reads |
The traps that make failover hard
Split brain. The network between the primary and standby breaks, but both are still running. The standby thinks the primary is dead and promotes itself. Now two servers both think they’re the primary and both accept writes, and the data drifts apart. The usual cures are a quorum (a majority must agree before anyone is promoted) and fencing (making sure the old primary is truly cut off). Coordination services like ZooKeeper exist largely to solve this.
Lost data. If the standby copy lags behind the primary, the last few seconds of writes may be missing after failover. Whether that’s acceptable depends on your recovery targets, covered in disaster recovery.
The backup that never worked. A standby nobody has tested can fail exactly when it’s needed: wrong settings, an expired certificate, not enough capacity. Teams that rely on failover practise it on purpose, regularly.
Failing back. Once the old primary is repaired, you may want to move traffic back. That’s another switch with its own risks, so many teams simply keep the new primary.
Common misconceptions
“With failover, there’s zero downtime.” There’s usually a short gap: time to detect, decide and switch. Good failover makes that gap small, not zero.
“A backup is the same as failover.” A backup is a saved copy you restore from, which can take hours. Failover switches to a live standby that’s ready now.
“Failover is only for databases.” Any part can fail over: load balancers, app servers, message brokers, even whole regions using DNS.
Key takeaways
- Failover switches work from a failed part to a backup.
- It removes single points of failure.
- Failures are detected with health checks and heartbeats, tuned to be neither too eager nor too slow.
- Active-passive keeps a standby ready; active-active uses every node and needs spare capacity.
- Watch for split brain, lost writes and untested backups.
Frequently asked questions
What is failover in simple words?
Failover means automatically switching to a backup when the main part of a system fails, so the service keeps running.
What is the difference between failover and high availability?
High availability is the goal: keeping a system up as much as possible. Failover is one of the main techniques for reaching that goal, by switching to backups when something breaks.
What is the difference between active-passive and active-active?
In active-passive, one server works while a standby waits to take over. In active-active, all servers work at the same time, and if one fails the others take its share.
What is split brain?
Split brain is when two servers both believe they are the primary at the same time, usually because the network between them broke. Both accept changes, and the data becomes inconsistent. Quorums and fencing prevent it.
How long does failover take?
It depends on the system. Removing a failed web server from a load balancer can take a few seconds. Promoting a standby database often takes seconds to a few minutes. Moving a whole region through DNS can take several minutes because of caching.
Comments