Module 6 · Reliability and infrastructureLesson 65 of 887 minIntermediate

Failover strategies

Failover moves work from a failed component to a standby. Doing it automatically is easy; doing it without ending up with two primaries is the hard part.

Try it

Watch "Automatic failover" and note the downtime. Then play "Split brain", and finally see how fencing prevents it.

Failover is switching from a failed component to a working one. It happens at every layer: load balancers, app servers, databases, whole regions.

Active-passive vs active-active

  • Active-passive: a standby is kept up to date but serves no traffic. On failure, it's promoted. Simple, but the standby is idle capacity, and you only find out whether it really works during a failure.
  • Active-active: every copy serves traffic all the time. A failure just means the others take more. Better use of resources, proves the spare works, but needs the app to handle multiple writers or careful data partitioning.

Anatomy of a failover

  1. Detect: health checks or heartbeats notice the primary is gone. Usually several seconds, to avoid false alarms.
  2. Decide: a monitor (or a consensus group) agrees a failover is needed.
  3. Promote: the standby becomes the new primary.
  4. Reroute: clients find the new primary, by moving a virtual IP, updating DNS (watch the TTL), or via a proxy that knows the current primary.

The total is your downtime. Managed databases typically fail over in 30 to 120 seconds.

Split brain

The monitor can't tell "the primary died" from "I can't reach the primary". If the old primary is alive but cut off, some clients may still write to it while others write to the new one. The data forks.

Defences:

  • Fencing / STONITH ("shoot the other node in the head"): cut the old primary's power or revoke its storage or network access before promoting.
  • Quorum: only a node that can reach a majority may act as primary.
  • Fencing tokens / epochs: storage rejects writes from an older primary's epoch.

Practise it

Run planned failovers regularly. A failover path you've never exercised is likely to fail when you need it, and your team should know what it looks like.

Quick check

What is split brain?