Ecommet
Topic 8 of 75

Availability Patterns: Fail-over and Replication

How systems stay up when machines fail: active-passive and active-active fail-over, leader-follower and multi-leader replication, and the traps that come with them, such as split brain and lost writes.

Intermediate 7 min read 4 quiz questions

Jump to the quiz

In a nutshell

  • Remove single points of failure: run at least two of everything that matters.
  • Active-passive: a standby takes over when the active node stops sending heartbeats. Active-active: all nodes serve traffic.
  • Leader-follower replication is simple and common; multi-leader accepts writes in several places but must resolve conflicts.
  • Fail-over risks split brain (two leaders) and lost writes (async replication); design for both.

Single points of failure

Any component that, if it fails, takes the whole system down is a single point of failure: one database server, one load balancer, one network link. High availability starts with finding them and adding redundancy, then making sure traffic actually moves to the healthy copy when one fails. That second part is fail-over.

Active-passive fail-over

One node (active) handles all traffic; a standby (passive) waits. They exchange heartbeats. If the standby stops hearing from the active node, it takes over the shared address and starts serving.

Active-passive fail-over

Active-passive fail-over Clients → Active: requests Active → Standby: heartbeat ✓ Active → Active: crashes Standby → Standby: no heartbeat for 10 s Standby → Standby: promote + take over IP Clients → Standby: requests ClientsActiveStandbyrequestsheartbeat ✓crashesno heartbeat for 10 spromote + take over IPrequests

All steps Only the active node serves. When its heartbeats stop, the standby promotes itself and takes over the address.

Diagram as text
  1. Clients send requests to the active node through a shared address (for example a virtual IP).
  2. The active node sends a heartbeat to the standby every second or so.
  3. The active node crashes.
  4. The standby notices that heartbeats have stopped for longer than a timeout.
  5. It promotes itself to active and claims the shared address.
  6. Clients now reach the new active node. They may have seen errors during the switch.
  • Simple to reason about: only one node writes at a time.
  • Wasted capacity: the standby sits idle until something breaks.
  • Downtime during the switch: detection timeout plus promotion, often seconds to a minute. A hot standby (already running, in sync) switches faster than a cold one (started on demand).

Active-active fail-over

All nodes serve traffic at the same time behind a load balancer (or DNS). If one fails, health checks remove it and the others absorb its share.

Active-active

Active-active Clients → Load balancer Load balancer → Node A: 100% now Load balancer → Node B: removed ClientsLoad balancerNode AhealthyNode Bfailed check100% nowremoved
Both nodes serve. When node B fails its health check, the load balancer stops sending it traffic.
Diagram as text
  • Clients → Load balancer
  • Load balancer → Node A: 100% now
  • Load balancer → Node B: removed

Every node is useful, and losing one only reduces capacity. The catch: each node must be able to take the extra load (plan for N + 1 capacity), and if the nodes hold data, writes on several nodes at once need coordination.

Replication

For stateless servers, fail-over is enough. For databases, the standby also needs a copy of the data, which is what replication provides. (The Databases module covers replication in depth.)

Leader-follower replication

Leader-follower replication App → Leader: writes Leader → Follower 1: replicate Leader → Follower 2: replicate AppLeaderreads + writesFollower 1readsFollower 2readswritesreplicatereplicate
Writes go to the leader, which streams changes to followers. Reads can be served by followers.
Diagram as text
  • App → Leader: writes
  • Leader → Follower 1: replicate
  • Leader → Follower 2: replicate
Leader-followerMulti-leader
Writes accepted byOne leaderSeveral leaders (often one per region)
ConflictsNone: one place decides the orderTwo leaders can change the same record; conflicts must be resolved
If the leader failsPromote a follower (fail-over)Other leaders keep accepting writes
Best forMost applicationsWrites in several regions, offline-capable apps

Synchronous replication waits for followers before confirming a write: no data loss on fail-over, but slower and stuck if a follower is down. Asynchronous replication confirms immediately: fast, but writes not yet copied are lost if the leader dies.

What goes wrong

Common mistakes

  • Adding a standby but never testing fail-over, then discovering on the day that it does not work.
  • Setting heartbeat timeouts too short, so a brief pause triggers fail-over and possible split brain.
  • Running active-active at more than about 50% each across two nodes: when one fails, the survivor is overloaded.
  • Using asynchronous replication for payments and losing confirmed writes on fail-over.

Interview questions

Try answering out loud before you open each one.

What is the difference between active-passive and active-active?

In active-passive, one node serves and a standby takes over when it fails; simple, but the standby is idle and fail-over takes time. In active-active, all nodes serve and a failed one is simply removed; better use of capacity and faster recovery, but each node must handle extra load and shared data needs coordination.

What is split brain and how do you prevent it?

Two nodes both believe they are the leader, usually because a slow or partitioned leader was declared dead. Both accept writes and the data diverges. Prevent it by electing leaders with a majority vote (an odd number of voters), and fencing the old leader so its writes are rejected, for example with increasing epoch or token numbers.

Check yourself

1. In active-passive fail-over, how does the standby usually detect failure?
Show the answer

Answer: Heartbeats from the active node stop. A missed heartbeat for longer than the timeout triggers the takeover.

2. What is the main drawback of asynchronous replication during fail-over?
Show the answer

Answer: Recently confirmed writes can be lost. Writes confirmed before they were copied disappear if the leader dies.

3. Two nodes both accept writes because each thinks it is the leader. What is this?
Show the answer

Answer: Split brain. Split brain: the data on the two sides diverges.

4. Two active-active nodes each run at 70% load. One fails. What happens?
Show the answer

Answer: The survivor needs 140% capacity and is overloaded. Plan for N + 1: each node must handle the load of a failed peer.

Further reading

Your notes

Saved in this browser as you type.

Finished this topic?

Mark it read to track your progress, then carry on with the next one.

Next topic