High Availability and Failover
How redundancy and failover keep services running, and the traps that make backups fail too.
Key takeaways
- Availability comes from removing single points of failure and detecting problems quickly.
- Active-active designs share traffic all the time, while active-passive designs keep a standby ready to take over.
- Data is the hard part, because copies can lag and two machines may both think they're in charge.
- Redundant parts that share a power source, location, configuration or bug can all fail together.
- Failover that isn't rehearsed should be treated as unproven.
High availability means designing a system so that it keeps working when parts of it break. Failover is the moment that design is used: traffic or work moves from a failed component to a healthy one. The core recipe is simple. Run more than one of anything you can't afford to lose, detect failure quickly, and switch over in a way that doesn't create a second problem.
The difficulty is in the details. A spare that was never tested, or a monitor that misjudges what's broken, can turn a small fault into a long outage.
Measuring availability
Availability is usually stated as the percentage of time a service works. Small differences in the percentage are large differences in downtime. Over a 365-day year, 99 percent allows about 3.7 days of outage. 99.9 percent allows a little under 9 hours. 99.99 percent allows about 53 minutes.
Basis: Arithmetic on a 365-day year of 8,760 hours.
Each extra nine tends to cost far more than the one before, since there's less and less time for a human to react. What 99.9 percent allows breaks down shorter periods, and service level agreements and error budgets shows how teams use these targets.
Time to recover matters as much as failure rate
Availability depends on two things: how often something breaks, and how long each break lasts. A component that fails rarely but takes a day to fix can be worse than one that fails monthly and recovers in seconds.
Break an outage into its stages: detecting the problem, deciding what's wrong, acting on it and confirming service is back. Shortening any stage helps. Automated detection removes the wait for a customer complaint. A written procedure shortens the deciding. A scripted switch shortens the acting. For tight targets, there's no time for a person to wake up and log in, so the first response has to be automatic.
Finding single points of failure
A single point of failure is any part whose loss stops the whole service. Walk the path of a request and ask at each step what happens if this disappears: the domain's DNS, the internet connection, the load balancer, the web server, the database, the storage, the power, the login provider, the person who knows the password.
Some are obvious. Others hide, such as one expired certificate, one payment account tied to a former employee, or a script that runs only on one old machine.
You don't have to eliminate every one. Rank them by how likely they are and how much they'd hurt, and be honest about the ones you choose to accept.
Redundancy patterns
In an active-passive arrangement, one component serves traffic while a standby waits. A hot standby is running and up to date, a warm one needs a little preparation, and a cold one must be started and loaded.
In an active-active arrangement, several components serve traffic together. Losing one reduces capacity, and there's no idle spare whose health is unknown. It requires that the instances can all do the work, which is easy for stateless web servers and much harder for databases that accept writes.
Engineers often describe capacity as N plus 1: you need N units to carry the load and keep one extra. With only two servers, each must be able to handle everything alone, so running both at 70 percent isn't really redundancy.
Detecting failure
Failover can't start until something notices. A health check is a regular probe: can this server open a connection, return a page, reach its database?
A load balancer uses health checks to stop sending requests to an unhealthy server. Good checks test something meaningful without being fragile. If every web server's check depends on one shared database, a database hiccup can mark all of them unhealthy at once, and the balancer has nowhere to send anyone.
Timing is a trade-off. Checking often and failing fast shortens outages but reacts to brief blips. Requiring several failures in a row before acting, and several successes before returning a server, prevents flapping between states.
Switching traffic
There are several levers for moving users, at different speeds.
- A load balancer can drop a server within seconds of failed checks.
- A floating or virtual IP address can move between machines on the same network, for example with VRRP between routers.
- DNS failover changes which address a name returns. It's broadly useful, but clients keep cached answers until their time to live runs out, and some hold them longer. The TTL change planner helps you think through the timing.
- Network routing, including anycast, can move traffic between sites when one stops announcing an address.
The data problem
Web servers are easy to replace if they hold no unique data. Databases aren't. A replica must receive every change from the primary.
With synchronous replication, a write isn't confirmed until another copy has it. You lose nothing on failover, but every write waits for the network, and a slow replica slows everyone. With asynchronous replication, the primary confirms right away and copies follow. It's faster, and a failover may lose the most recent writes.
The nastiest case is split brain. The network between two database servers breaks, each assumes the other died, and both accept writes. Reconciling the two histories can be painful or impossible. Systems guard against this with quorum, where a node may act as leader only if a majority agrees, which is why clusters often use an odd number of members or add a small witness. Fencing, which forcibly cuts off the old primary, is another safeguard.
State beyond the database
Plenty of other things quietly live on a single server. Login sessions kept in a web server's memory vanish when it dies, and users find themselves signed out. Uploaded files saved to a local disk disappear from view after a switch.
Move that state somewhere the replacements can reach it: sessions in a shared cache or a signed token, files in shared or object storage, configuration in version control. Once a server holds nothing unique, you can replace it without ceremony, and failover for that tier becomes routine.
Scheduled jobs need thought as well. If two active servers both run the nightly billing task, customers may be charged twice. If only one runs it and that one dies, nobody is billed. Use a shared lock or a scheduler that guarantees a single active runner, and make the job safe to run again.
Shared fates
Two servers in one rack share a power strip and a network switch. Two data halls may share a utility feed. Cloud providers offer availability zones designed to fail independently, and regions spread farther apart for larger events.
Not all shared fate is physical. The same bad configuration pushed everywhere, the same software bug triggered by the same date, one expired credential, or one provider's control system can take out every copy. Roll changes out in stages and keep an emergency way in that doesn't depend on the system you're trying to repair. How cloud outages cascade looks at this effect.
Degrading instead of dying
Availability isn't only on or off. A shop can keep selling while recommendations are hidden. A news site can serve slightly old cached pages while its editing system is down.
Decide which features are essential and what the others should do when unavailable. Set timeouts so a stuck dependency doesn't tie up every worker. A circuit breaker, which stops calling a failing service for a while and then tests it again, keeps one fault from spreading.
Testing your failover
Schedule drills. Stop a server and watch what happens. Promote a database replica. Time the whole process, including the part where someone has to notice and decide.
Check what happens on the way back, too. Returning to the original primary can be riskier than the first switch, since it must catch up before it can lead.
Write down the steps, who can authorize them and how to undo them. Automatic failover is good for clear failures. For ambiguous ones, some teams prefer that a person confirms, accepting a slower recovery to avoid a wrong one.
A small example design
Say you run a booking website and can tolerate a few minutes of disruption but not hours. A reasonable design might put two identical web servers in separate availability zones behind a managed load balancer. The database runs with a standby in the second zone and automatic promotion. Uploaded files go to object storage, and sessions live in a replicated cache.
If one web server fails, the balancer stops using it and an automatic group starts a replacement. If a whole zone fails, the other web server carries the load, the standby database takes over, and users may see errors for a short while. This design doesn't survive the loss of the entire region. Covering that would mean a second region, data replicated over distance and a deliberate decision about whether the extra cost and complexity are justified.
What high availability doesn't do
Redundancy faithfully copies mistakes. If someone deletes a table, the replica deletes it too. You still need backups and a disaster recovery plan.
It also adds complexity, and complexity causes outages of its own. A single well-maintained server with fast, rehearsed restoration can be a reasonable choice for a small project where an hour of downtime is only an inconvenience.