Skip to content
Episode 81 · 2:14 a.m., zone A

Redundancy and failover

Wednesday, 2:14 a.m.: the database host in zone A dies. A healthy standby sits ready in zone B, but nothing switches to it, and every booking fails for 41 minutes while Omar wakes up and follows a runbook.

Machines break all the time. Here's how to keep the service running when one does, without making things worse.

30 min advancedN+1 redundancy and capacity headroomActive-passive vs active-activeFailure detection and automatic failoverPreventing split brainHealth checks (liveness/readiness)Multi-AZ vs multi-region deployment
  1. Problem

    At 2:14 a.m. the database host's disk controller dies. Every booking fails until someone wakes up, diagnoses it and rebuilds the server, about two hours later.

  2. Why the simple system fails

    One copy of anything is a single point of failure. A second copy that nobody can switch to quickly, or that switches by itself at the wrong moment, doesn't fix it.

  3. Engineering concept

    Run spare capacity (N+1) in independent failure domains, detect failures automatically with health checks, and fail over to a standby or shift load to active peers, with a quorum and fencing so only one leader ever accepts writes.

  4. Technology

    Load balancer health checks, multi-AZ instance groups, database standbys with automatic promotion (managed services, Patroni-style managers), witnesses and quorums, fencing, DNS or proxy re-routing.

  5. Trade-offs

    Redundancy costs idle capacity and complexity. Fast failover risks false positives and split brain; cautious failover means longer outages. Async standbys can lose the last writes.

01

The problem

2 min
Wednesday, 9:00. The morning after.
  1. Omar · On-call SRE
    Primary died at 02:14. Bookings failed for 41 minutes. The standby was fine; I was the slow part.
  2. Karim · CTO
    41 minutes is almost the whole month's budget. Make it automatic.
  3. Omar · On-call SRE
    Easy: if the standby can't reach the primary for 10 seconds, it promotes itself.
  4. Lina · Senior engineer, your mentor
    You draft the design this time. What could that rule do wrong?
02

The big idea

4 min
A standby nobody switched to
The big idea

Redundancy needs automatic , and failover needs a majority and fencing. A spare nobody can switch to is just an expensive spare part.

The machine part of Wednesday night took seconds; the human part took 41 minutes. Automate it, but safely.

03

How it works

5 min
Safe automatic failover
  1. 1
    Detect

    Health checks every 10 s; the primary must renew a 30-second . Three misses means trouble.

  2. 2
    Agree by majority

    Standby in zone B + witness in zone C = 2 of 3 votes, a . An isolated node can never win alone.

  3. 3
    Fence the old primary

    Its lease has expired, so it stops accepting writes, even if it's alive behind a broken link. That prevents : two leaders accepting different writes.

  4. 4
    Promote the standby

    Only a synchronous standby, which has every confirmed booking. One writer and a waiting standby is active-passive.

  5. 5
    Re-route clients

    A connection proxy points at the new primary; apps reconnect in seconds. A DNS name with a 300 s TTL would be the slowest phase.

  6. 6
    Restore redundancy

    We're on one node now. Build a new standby, and keep alerting until it exists.

The app servers are the easy half: , so they run active-active, all serving, and a dead one is just skipped. But size them N+1: losing a zone must leave enough capacity.

04

Watch a decision being made

4 min
Worked example

You draft StayHub's failover design, Lina reviews

Make losing a server, a database node or a whole zone cost seconds, not 41 minutes. Today: 4 app servers in zones A and B at ~75% CPU at peak; primary in A, sync standby in B, manual promotion.

  1. 1Size N+1 per zone

    Peak needs 3 servers' worth; losing zone A leaves 2 needing 150%. Move to 3 zones × 2 = 6: losing any zone leaves 4 at ~75%.

    Why: Lina: "two of everything isn't enough if the survivors can't carry the load."

  2. 2Majority, lease, in-sync only

    Witness in zone C, 2 of 3 votes, 30 s lease; promote only while the standby is in sync.

    yaml
    ttl: 30                 # leader lease
    loop_wait: 10           # renew / check every 10 s
    synchronous_mode: true  # only a sync standby can be promoted

    Why: A cut-off node can't elect itself, the old primary steps down alone, and no confirmed booking is lost.

  3. 3A stable endpoint for apps

    Apps connect through a proxy the failover manager updates, not the DNS name.

    Why: Detection and promotion take ~40 s; a 300 s DNS cache would dwarf them.

  4. 4Drill it every quarter

    Kill the primary in a drill, time it end to end (~30 s + ~10 s + ~5 s: under a minute), count bookings before and after.

    Why: Untested failover fails when you need it.

The whole thing in one line: 6 app servers over 3 zones, and a fenced, majority-voted, synchronous active-passive database behind a proxy: a zone loss now costs under a minute and no confirmed booking.
05

In real life

3 min
Two well-known approaches

Netflix: active-active, shift the load

  • Has publicly described serving from several regions at once and moving traffic off a failing one
  • Works because most services are stateless and its data stores accept writes in several places
  • No promotion step

Fits when copies can accept writes without conflicts that matter.

GitHub: one writer, automatic promotion

  • Runs MySQL with a single primary and automated failover tooling
  • Its public October 2018 report describes a 43-second network interruption leading to a cross-site promotion
  • Writes landed on both sides; repair meant about a day of degraded service

Single-writer is safer for data like ours, if promotion is fenced and scoped.

06

What goes wrong

3 min
Automatic failover with two nodes and no witness

A broken link looks exactly like a dead peer: split brain.

Instead

An odd number of voters, a majority, fencing before promotion.

N+1 on paper, N in practice

Survivors at 150% can't absorb a lost zone.

Instead

Stay under ~70–80% after losing a zone.

Never testing failover

Standbys drift, TTLs are longer than assumed, pools hold dead connections.

Instead

Regular timed drills; fix what breaks.

07

Trade-offs

3 min
Active-passiveActive-active
WritersOne: no conflictsSeveral: conflicts to handle
Spare capacityIdle standbyAll used, each with headroom
On failureSeconds to promote, fencedLoad just shifts
FitsDatabases, inventory, paymentsStateless tiers, data built for it
Friday, 10:00. The cloud bill arrives.
  1. Karim · CTO
    We pay for a full-size standby that does nothing all day. Let both zones take bookings.
  2. Lina · Senior engineer, your mentor
    Two writers for room inventory means two guests can book the last room in the same second.
  3. Karim · CTO
    Then lock rooms per zone, or fix conflicts afterwards. Idle hardware is money burning.
08

Your job as tech lead

4 min

Claude Code can write the code for this. You still own the decisions, and you have to know what good looks like to accept or reject its work.

Decisions you own
  • Sizing for a lost zone: 6 servers across 3 zones is a cost you choose, not something to trim later "because they're idle".
  • Keeping the standby synchronous (~1.5 ms per write) so no confirmed booking is lost.
  • Who may promote: 2 of 3 votes with a witness in zone C and a 30 s lease. Never "whoever can't see the primary".
Tell Claude Code
Plan only, no changes yet: we're replacing the manual database promotion that cost us 41 minutes this week. Target: sync standby in zone B, witness in zone C, promotion needs 2 of 3 votes, lease TTL 30 s, the old primary fenced before promotion, apps connecting through the connection proxy, not the DNS name (300 s TTL). List what changes, step by step, with rollback. Then write a staging drill: stop the primary, measure detection, promotion and re-route times, and check no booking confirmed before the stop is missing afterwards.
Check before you accept
  • The order: detect, agree (2 of 3), fence, promote, re-route, rebuild. Fencing missing or after promotion: reject.
  • The drill timeline: ~30 s + ~10 s + ~5 s, under a minute.
  • No lost booking proven by a count before and after, not "looks fine".
Red flags
  • Automatic promotion with two nodes and no witness.
  • Switching the standby to async "for performance" without saying it can lose confirmed bookings.
  • Adding every dependency to the readiness check "to be thorough".
09

Check yourself

2 min
Q1/3Reasoning
Peak load needs 6 app servers. You run in 3 availability zones with the same number of servers in each, and must survive losing a whole zone at peak. What's the minimum total number of servers?
servers
How confident are you?

Next episode: a migration sets every hotel's price to €0, the standby copies it perfectly, and you lead the recovery.

Finished?

Mark it complete to update your skill map.

Go deeper (optional)You don't need this to understand the lesson. Open it when a project needs the details: Technical deep dive, Interactive simulation, Visual diagram, Analogy, Check your understanding, Practice ladder, Explain it yourself.
10

Technical deep dive

Timing a failover end to end
Worked example

You draft StayHub's failover design, Lina reviews

Make sure losing a server, a database node or a whole zone in Frankfurt costs StayHub seconds, not 41 minutes. Today: 4 app servers in zones A and B at ~75% CPU at peak; a primary in A with a synchronous standby in B (set up in the scalability module) and manual promotion.

  1. 1List the single points of failure

    The DB primary (manual promotion), and the app tier: peak needs 3 servers' worth of capacity, and losing zone A leaves 2 servers needing 150%.

    Why: Lina's review note: "Two of everything isn't enough if the survivors can't carry the load."

  2. 2Size N+1 per zone

    Move to 3 zones × 2 servers = 6. Losing any zone leaves 4 servers at ~75% CPU, the same as today's peak.

    Why: N+1 is about the failure you plan to survive. Surviving a zone means each zone's share must be spare.

  3. 3Promote only an in-sync standby

    The zone-B standby is already synchronous. Tell the failover manager to promote it only while it's in sync, never a copy that has fallen behind.

    Why: A standby that is behind (or async) may not have the last bookings a guest saw confirmed. We already pay ~1.5 ms per write for sync; losing confirmed bookings would cost far more.

  4. 4Add a majority and fencing

    A witness in zone C. Promotion needs 2 of 3 votes. The primary holds a 30 s lease; once it expires, it refuses writes.

    yaml
    ttl: 30                 # leader lease: not renewed within 30 s → leadership lost
    loop_wait: 10           # renew / check every 10 s
    synchronous_mode: true  # only a synchronous standby can be promoted
    # coordination store: 3 members across zones A, B, C

    Why: Majority stops a cut-off node from electing itself; the lease makes the old primary step down on its own.

  5. 5Give apps a stable endpoint

    Apps connect through a database proxy that the failover manager updates, instead of a DNS name with a 300 s TTL.

    Why: Detection and promotion take ~40 s. A 300 s DNS cache would make re-routing the slowest phase by far.

  6. 6Drill it and restore redundancy

    Kill the primary in a drill every quarter, time it end to end, and automatically build a new standby afterwards.

    Why: Untested failover fails when you need it. And after a failover we're on one node: a second failure would be a full outage.

The whole thing in one line: Your design spreads 6 app servers over 3 zones so any one can fail, and turns the database into a fenced, majority-voted, synchronous active-passive pair behind a proxy: a zone loss now costs under a minute and no confirmed booking.
Failover phaseTypical durationWhat controls it
Detection5–30 sCheck interval × failure threshold, lease TTL
Decision (majority agrees)< 1–5 sCoordination store latency
Fencing old leader< 1–10 sLease expiry, network or storage isolation
Promotion1–10 sReplaying the remaining log on the standby
Re-routing clientsseconds to minutesProxy or virtual IP (fast) vs DNS TTL (slow)
Measure the whole failover in drills; it's usually longer than the sum of the settings.
11

Interactive simulation

12

Visual diagram

Click a component

Active-active app tier across three zones, active-passive database with a witness. Run the walkthrough to see a primary failure.

13

Analogy

  • Flying a planeCan still fly with one engine outRunning a serviceOne extra server: losing one is fine
  • Flying a planeCaptain flies, co-pilot ready to take overRunning a serviceActive-passive: a standby waits
  • Flying a planeCo-pilot cross-checks the instrumentsRunning a serviceHealth checks watch each copy
  • Flying a planeClear spoken handover: "Your controls"Running a serviceSafe failover with a single leader
  • Flying a planeBoth pilots steering different waysRunning a serviceSplit brain: two leaders, conflicting data

Where the analogy breaks: pilots can see and talk to each other. Servers often can't tell if their partner is dead or just unreachable, which is exactly why split brain happens.

14

Check your understanding

Q1/3Reasoning
Put the steps of a safe automatic database failover in order:
  1. 1.Primary misses heartbeats / fails to renew its lease
  2. 2.A new standby is created to restore redundancy
  3. 3.Old primary is fenced so it can't accept writes
  4. 4.A majority of voters agrees the primary is gone
  5. 5.The most up-to-date (synchronous) standby is promoted
  6. 6.The database endpoint is switched and clients reconnect
How confident are you?
15

Practice ladder

Step 1 · Trace

Trace a 15-second network split

Scenario Warm-up

StayHub's reviews service has two database nodes and no witness: a primary in zone A and a standby in zone B. Rule: the standby promotes itself if it can't reach the primary for 10 seconds.

At 11:00:00 the network link between zones A and B drops for 15 seconds. App servers in zone A can still reach the primary; app servers in zone B can only reach the standby.

Trace what happens second by second until 11:00:30, and what state the data is in afterwards.

Step 2 · Complete

Fix the order of Omar's runbook

Design Practice

Omar wrote the automatic failover steps for the payments database, but one is missing and two are swapped. Put them in the right order and add the missing step.

  • A. Promote the standby to primary
  • B. Point the database proxy at the new primary
  • C. Detect: the primary missed 3 health checks and its lease renewals
  • D. The failover manager and the standby agree (2 of 3 votes) the primary is gone
  • E. Build a new standby and alert until it's in sync
  • F. ___
Step 3 · Solve

Size the search fleet for a lost zone

Estimation Practice

The search API needs 8 app servers at peak (each sized to run at ~70% CPU). Each server costs about €200 a month. StayHub must survive losing a whole zone at peak without slowing down.

  1. How many servers, and what monthly cost, with 2 zones? With 3 zones?
  2. Which would you pick, and what else must be true for the zone spread to actually help?
Step 4 · Decide

Sync standby for the reviews database?

Decision Stretch

The reviews database (guest reviews of hotels) has an async standby and manual promotion. Two options:

  • A. Same as bookings: sync standby, witness in zone C, automatic fenced failover. About €700/month more and ~1.5 ms added to each review write.
  • B. Keep async, but automate promotion with a witness and fencing. Failover in under a minute; may lose the last few seconds of reviews.

Reviews are written about 20 times a minute. A lost review means a guest re-types it (we can email them). Write a short decision: "We chose X over Y because…, accepting the risk of…".

16

Explain it yourself

Explain how you'd make a booking system survive the loss of a server, a database node and a whole availability zone, and what could go wrong during failover.

0 words