SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
  • Scalability
  • Availability
  • Reliability
  • Single Point of Failure (SPOF)
  • Latency vs Throughput vs Bandwidth
  • Consistent Hashing
  • CAP Theorem
  • Fault Tolerance and Redundancy
  • Failover
  • Stateless vs Stateful
  • Concurrency vs Parallelism
  • Capacity Planning
  • Back Pressure
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Foundations/Core Concepts

Failover

Switch to a backup when the main system fails: active-passive and active-active.

โฑ 13 min readIntermediateMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Failover means that when the main part of a system fails, a backup takes over automatically, so users see little or no break in service.

  • In active-passive, one machine works and a standby waits. When the active one fails, the standby is promoted.
  • In active-active, all machines work at the same time. When one fails, the others simply take its share.
  • Failover needs three things: a way to notice the failure, a way to switch, and a backup that has the data it needs.

02Concept: What is it?

Every machine fails some day. Failover is the plan for that day. You keep a spare, you have a way to detect that the main one is gone (usually with heartbeats: small "I am alive" messages), and you redirect traffic to the spare (by moving a virtual IP, changing a DNS record, or telling the load balancer to stop using the dead machine).

The total break users feel is: time to detect + time to switch. Detection is a trade-off. If you wait for many missed heartbeats you avoid false alarms but users wait longer. If you react to one missed heartbeat, a short network hiccup can trigger a needless switch.

Two ways to be ready
Active-passive
๐Ÿ–ฅ๏ธActiveserves all traffic
โ†”heartbeat + copy data
๐Ÿ’คStandbywaits
Active-active
๐Ÿ–ฅ๏ธNode 1serves half
๐Ÿ–ฅ๏ธNode 2serves half
โ†‘load balancer spreads traffic
Active-passive keeps a spare idle. Active-active uses every machine all the time.
๐Ÿง Redundancy is not failover
Having a spare machine (redundancy) is only half of the job. Failover is the automatic switching that makes the spare useful. A spare that nobody tests or switches to is just a cost.

03Real-Life Example

๐ŸตThe Spare Pilot and the Two Bus Drivers
A passenger plane has a pilot and a co-pilot. Only one flies at a time, but the co-pilot watches everything, so if the pilot faints the co-pilot takes the controls within seconds. That is active-passive with a hot standby. A city has two bus drivers sharing one long route, each driving half of the buses. If one driver goes home sick, the other must now run all the buses, and the buses are crowded until a new driver arrives. That is active-active: no one sits idle, but the survivor needs room to take more.
Pilot and co-pilot / bus drivers
Failover
The pilot flying
The active node
The co-pilot watching, ready to take over
A hot standby
Noticing the pilot has fainted
Failure detection (heartbeats)
Taking the controls
Promotion of the standby
Two drivers each with half of the buses
Active-active
The survivor now has too many buses
Survivors need spare capacity
A co-pilot who never practised
A standby that was never tested
What happens in a failover
๐Ÿ’ฅActive failscrash or hang
โ†’โ†“
๐Ÿ‘€Detectmissed heartbeats
โ†’โ†“
โฌ†๏ธPromotestandby becomes active
โ†’โ†“
๐Ÿ”€Redirecttraffic moves
โ†’โ†“
โœ…Serving again

04Why Do We Need It?

โฑ๏ธShort downtime
Automatic failover turns an outage of hours (waiting for a human) into seconds.
๐ŸŽฏMeet your uptime goal
You cannot reach four nines (about 52 minutes of downtime a year) if every failure needs a person to wake up.
๐ŸงฏRemove single points of failure
A spare for every important part means one break does not stop the whole system.
๐Ÿ”งSafe maintenance
Move traffic to the other node, patch the first one, then switch back.
๐ŸŒSurvive big disasters
Fail over to another data centre or region when a whole site goes dark.
๐Ÿ˜ดFewer night alarms
The system heals itself first. Humans look at the cause later.
Machines will fail. Failover decides whether users notice for seconds, for hours, or not at all.

05Where Do We Use It?

๐Ÿ—„๏ธDatabases
A primary with a replica that is promoted when the primary dies (managed databases do this for you).
โš–๏ธLoad balancers
A pair of balancers sharing one virtual IP, so the balancer itself is not a single point of failure.
๐ŸŒDNS and regions
Health-checked DNS records or global load balancers send users to a healthy region.
๐Ÿง Cluster managers
Tools such as Kubernetes restart failed pods on other machines and reschedule work.
๐ŸฆPayments and banking
Core systems run in two sites, often with strict rules about data copies.
๐Ÿ”ŒPower and network
Two power feeds, two network cards, two switches: the same idea, in hardware.

06Types / Parts / How It Works

Active-passive and active-active

Active-passiveActive-active
Who serves trafficOnly the active nodeAll nodes
On a failureDetect, promote the standby, redirectRemove the failed node, the others absorb the load
Typical downtimeSeconds to minutes, depends on the standbyOften none, or only until the health check notices
Spare capacityA whole machine sits idleEvery node must keep headroom
DataStandby copies data from the active oneData must be shared or replicated both ways, and conflicts handled
ComplexitySimpler. Watch out for split brainHarder. Needs a good load balancer and data design

How ready is the standby?

StandbyStateTakeover timeCost
HotRunning, data kept in sync all the timeSecondsHighest (a full machine, always on)
WarmRunning, but data is a little behind or services are not all startedTens of seconds to minutesMedium
ColdSwitched off or empty. Must be started and loaded from backupsMinutes to hoursLowest
The break users feel
Detect (3 missed heartbeats)e.g. 9 s
Promote a hot standbye.g. 2 s
Promote a cold standbye.g. minutes
Detection Hot Cold
Shorter detection and a hotter standby both cut the outage.
VisualizerCrash a machine: active-passive vs active-activeCrash machine A at second 10. Try a hot, warm and cold standby, then slow down the heartbeat. Switch to active-active and push the traffic above 100 req/s.
Which design?
How ready is the standby?
๐Ÿ–ฅ๏ธMachine Acrashed
โ†”
๐Ÿ–ฅ๏ธMachine Bhas not noticed yet
Requests served each second (one column per second, A crashes at second 10). Green = all served, amber = some lost, red = none served.
0 s60 s120 s
Full outage
11 s
nobody served
Failed requests
880
in 120 s
Availability
90.83%
in this window
Survivor load
80%
one machine alone
Max traffic when healthy
100 req/s
standby sits idle
The standby only starts serving after it notices the crash (9 s: 3 s heartbeat ร— 3 missed) and takes over (2 s). For 11 s nobody serves requests.

Illustrative model: each machine serves 100 req/s, takeover times are made-up round numbers (hot 2 s, warm 20 s, cold 90 s), and no random numbers are used. Real systems differ.

07How to Use It / Steps / Implementation

Building a failover that really works

  1. 1
    Find what can fail
    List the parts: servers, databases, load balancers, network links, a whole site. Give each one a plan.
  2. 2
    Choose a design per part
    Stateless web servers fit active-active well. Databases with one writer usually use active-passive with a promoted replica.
  3. 3
    Detect quickly but carefully
    Use heartbeats or health checks. Ask for several missed checks, so a short hiccup does not trigger a switch.
  4. 4
    Make the switch automatic
    Use a virtual IP, a health-checked load balancer or a managed service, so no human is in the critical path.
  5. 5
    Keep the standby in sync
    Replicate data to it. Check how far behind it is, because that lag is the data you may lose.
  6. 6
    Prevent two leaders
    Use a quorum, a lease or fencing, so the old active node cannot keep working after the standby took over (split brain).
  7. 7
    Leave headroom
    In active-active, size the nodes so the survivors can carry the load. With 2 nodes, each should run below half of its capacity.
  8. 8
    Practise failing
    Test failover on a schedule (game days, chaos tests). A failover you have never run will probably not work.
โš ๏ธSplit brain
If the standby only thinks the active node is dead (a network problem, not a crash), both may start serving and writing. Data becomes inconsistent. Use fencing, leases or a majority vote to make sure that only one leader exists.
๐Ÿ’กFailback is also a plan
After repair, the old node must come back as the standby, not take over again without care. Many outages come from a messy failback.

08Key Terms to Know

TermMeaning in easy words
FailoverAutomatically switching to a backup when the main part fails
FailbackMoving back to the original node after it is repaired
Active-passiveOne node serves, a standby waits and takes over on failure
Active-activeAll nodes serve at the same time, and the survivors absorb a failed node's load
Hot / warm / cold standbyHow ready the backup is: running and in sync, partly ready, or switched off
HeartbeatA small regular message that says the sender is alive
Failure detectionHow the system decides that a node is dead (for example, 3 missed heartbeats)
Virtual IPAn address that can be moved to another node, so clients do not need to change anything
Split brainTwo nodes both believe they are in charge, and both accept writes
FencingBlocking the old active node from writing after a new one took over
RTO / RPOHow long you can be down (recovery time) and how much data you can lose (recovery point)

09Pros, Cons and Trade-offs

โœ… Pros
  • Short, often invisible, downtime
  • No waiting for a human at night
  • Makes planned maintenance easy
  • Helps you reach a high uptime goal
  • Works from a single disk up to a whole region
โš ๏ธ Cons
  • Extra hardware that costs money
  • More moving parts to test and monitor
  • False alarms can cause needless switches
  • Data copies may lag, so a little data can be lost
  • Split brain if it is designed badly

Trade-offs

ChoiceWe gainWe lose
Hot standbyTakeover in secondsPay for a machine that is idle most of the time
Cold standbyCheapLong outage while it starts and loads data
Quick detectionShort outageMore false alarms and needless switches
Slow detectionFew false alarmsUsers wait longer before the switch
Synchronous copy to the standbyNo data loss on failoverSlower writes, and a slow standby slows the active node
Asynchronous copyFast writesThe newest writes may be lost on failover
Active-activeUse all hardware, almost no downtimeHarder data design and needs headroom

10Common Problems and Mistakes

Common mistakes

  1. Never testing it. The first real failover turns out to be broken, in the middle of an incident.
  2. Split brain. The standby takes over while the old node is still alive, and both write.
  3. Standby too small. The spare cannot carry the real load, so it fails too.
  4. No headroom in active-active. Two nodes at 70% each cannot be reduced to one. The survivor overloads and fails (a cascade).
  5. Ignoring replication lag. The promoted node is behind, and recent writes disappear.
  6. The failover mechanism is a single point of failure. One monitor or one balancer decides everything.
  7. Flapping. A weak health check switches back and forth, and that causes more damage than the first failure.

Things to watch

๐Ÿ”Flapping
Add a hold-down time: do not switch back for a while after a switch.
๐Ÿ“‰Replication lag
Alert when the standby is far behind. That is your data-loss risk.
๐ŸงชUntested standby
Run game days. Check that config, credentials and capacity match.
๐ŸŒŠThundering herd
After a switch every client reconnects at once. Use retries with backoff and jitter.

11Real-World Examples

๐Ÿ˜PostgreSQL clusters
Tools such as Patroni manage a primary and replicas, and promote a replica when the primary is lost.
โ˜๏ธManaged databases
Cloud databases offer a multi-zone option with an automatic standby and failover.
๐ŸŸฅRedis Sentinel
Watches a Redis primary and promotes a replica if the primary stops answering.
โš“Kubernetes
Replaces failed pods and moves work from a lost node to other nodes.
๐ŸŒMulti-region apps
Health-checked DNS or a global load balancer routes users away from a failed region.
๐Ÿ”ŒVirtual IP pairs
Tools such as keepalived (VRRP) move one IP between two balancers.
๐Ÿ“Note
Product names and defaults change between versions. Treat these as examples and read the docs for the exact behaviour.
Mini case: a database with a replica
๐Ÿ—„๏ธPrimarycrashes
โ†’โ†“no heartbeat
๐ŸงญMonitor3 missed = dead
โ†’โ†“promote
๐Ÿ—„๏ธReplicanow primary
Failed Detection New primary
Detection and promotion decide how long writes are unavailable.

12Related Topics to Read Next

Fault Tolerance and Redundancyโ†’

Failover is the switching part of a fault-tolerant design.

Single Point of Failure (SPOF)โ†’

Failover is how you remove a SPOF.

Availabilityโ†’

Faster failover means more nines.

Heartbeatsโ†’

How a failure is noticed.

Split Brain Problemโ†’

What goes wrong when failover is not careful.

Replicationโ†’

Keeps the standby's data close to the active node's.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • โœ”What: automatic switch to a backup when the main part fails.
  • โœ”Active-passive: one serves, standby waits. Simple, idle spare, some downtime.
  • โœ”Active-active: all serve. Survivors need headroom (2 nodes: under 50% each).
  • โœ”Outage = detection time + switch time. Hot standby: seconds. Cold: minutes or more.
  • โœ”Detect: heartbeats, with several missed beats before acting, to avoid false alarms.
  • โœ”Danger: split brain. Use quorum, leases and fencing.
  • โœ”Data: replication lag is the data you may lose (RPO). Sync copy trades speed for safety.
  • โœ”One line: โ€œA spare is not enough. Detect fast, switch automatically, and practise it.โ€
โ† Previous
Fault Tolerance and Redundancy
Next โ†’
Stateless vs Stateful