High availability and failover
Overview
Hardware fails, networks partition, data centres lose power and people deploy bugs. A highly available (HA) system keeps working through these failures, usually without anyone noticing. This lesson turns the availability maths from week 1 into concrete architecture: redundancy, failure domains and failover.
Redundancy at every layer
The principle is simple: no component should be the only one of its kind. For each layer:
- Entry point: DNS with health checks; a managed load balancer that runs across zones.
- App servers: several stateless instances in an autoscaling group, spread across zones.
- Caches: a replica per shard, with automatic promotion.
- Databases: a standby (or replicas) in another zone with automatic failover.
- Queues and storage: managed services that replicate across zones (most do by default).
Failure domains
Redundancy only helps if copies don’t fail together. A failure domain is a set of things that can fail at the same time:
- a single machine or disk,
- a rack (shared power and network switch),
- an availability zone (AZ): one or more data centres with independent power, cooling and networking, a few kilometres from the others in the same region,
- a region: a whole geographic area, such as Mumbai or Frankfurt.
Zones in a region are connected by fast, low-latency links (typically a millisecond or two), so you can replicate synchronously between them. Regions are far apart, so cross-region replication is usually asynchronous. A common standard is multi-AZ for everything, and multi-region only for systems whose downtime is very expensive.
Remember non-physical failure domains too: a bad config or a buggy release can break every copy at once. Roll out changes gradually, zone by zone.
Active-passive vs active-active
Active-passive (primary/standby): one copy serves traffic; the other waits, kept up to date, ready to take over.
- Simple to reason about, especially for databases: only one node accepts writes.
- The standby costs money while idle.
- Failover takes time (seconds to minutes) to detect and switch.
Active-active: all copies serve traffic at the same time.
- Uses all capacity, and losing one copy just means the others take more load.
- Natural for stateless app servers.
- Hard for writable data: if two copies accept writes to the same record, they can conflict (week 5).
Rule of thumb: stateless tiers are active-active; databases are usually active-passive per shard, with read replicas for extra read capacity.
How failover works
Failover has three steps:
- Detect the failure: health checks or heartbeats stop answering for a set time.
- Decide which copy takes over, ideally with an independent observer or a consensus system, so a temporary network glitch doesn’t cause a false failover.
- Redirect traffic: update DNS, move a virtual IP, or update service discovery, and promote the standby to primary.
Two dangers to name in interviews:
- Split brain: the old primary isn’t dead, just cut off. If it keeps accepting writes while the new primary does too, data diverges. Systems prevent this with fencing (cutting the old primary off from storage or clients) and with consensus or leases so only one node can be leader (week 5).
- Data loss on failover: with asynchronous replication the standby may be a few seconds behind, so the last writes can be lost. Synchronous replication avoids that but adds latency to every write.
Health checks that tell the truth
A health check should reflect whether a server can actually do its job:
- Liveness: is the process running? Restart it if not.
- Readiness: can it serve traffic now (connected to the database, caches warmed)? Remove it from the load balancer if not.
Avoid deep checks that fail when a shared dependency is down. If every server reports unhealthy because the database blipped, the balancer removes all of them and turns a partial outage into a total one.
Graceful degradation
High availability isn’t only about keeping every feature up. It’s also deciding what to show when something fails:
- show cached or slightly stale data,
- hide a broken recommendation panel instead of failing the whole page,
- accept orders into a queue and process them when the payment provider recovers.
Week 6 covers circuit breakers, timeouts and fallbacks that make this possible.
Test it
Failover that has never been exercised often fails when it’s needed: a standby with expired credentials, a DNS TTL of a day, a runbook nobody remembers. Teams practise with planned failovers, game days and chaos engineering tools that deliberately kill instances or zones in production.
In an interview
After the high-level design, go through your diagram and say how each part survives a failure: “App servers are spread across three zones; the database has a synchronous standby in a second zone with automatic failover; Redis has a replica; if a whole zone fails we lose a third of app capacity and autoscaling replaces it.” Mention split brain and data loss if you discuss database failover.
Recap
High availability comes from redundancy at every layer, spread across independent failure domains, with automatic detection and failover. Stateless tiers run active-active; databases usually run active-passive with replicas. Guard against split brain and data loss, design health checks carefully, degrade gracefully, and test failover before you need it.
Find and fix the single points of failure
A small SaaS app runs in one cloud region: one load balancer instance, three app servers all in availability zone A, one PostgreSQL server in zone A with nightly backups to object storage, and one Redis server for sessions. List every single point of failure, and describe a highly available version of the same system. Then say what failure your new design still can't survive.
Single points of failure:
-
Highly available version:
-
Still can't survive:Single points of failure:
- The single load balancer instance.
- Zone A itself: all app servers, the database and probably Redis live there.
- The single PostgreSQL server (nightly backups mean up to 24 hours of data loss
and hours to restore).
- The single Redis server: if it dies, everyone is logged out.
Highly available version:
- Managed load balancer spanning three zones (or two self-managed instances).
- App servers in an autoscaling group spread across zones A, B and C.
- PostgreSQL primary in zone A with a synchronous standby in zone B and automatic
failover (e.g. a managed multi-AZ database); read replica optional.
Keep continuous backups / point-in-time recovery for mistakes.
- Redis with a replica in another zone and automatic failover (or a managed
multi-AZ Redis); sessions could also be signed tokens.
- Health checks everywhere, and alerts when failover happens.
Still can't survive: a full regional outage, a bad deploy or bad data change that is
replicated everywhere, or an outage of a shared dependency (DNS, identity provider).
Surviving a region loss needs a second region (week 6, disaster recovery).Summary
- High availability comes from redundancy at every layer plus automatic failure detection and failover.
- Spread copies across failure domains: different machines, availability zones and, for the most critical systems, regions.
- Active-passive keeps a standby ready to take over; active-active serves traffic from every copy at once.
- Failover needs reliable failure detection and protection against split brain, where two nodes both think they are primary.
- Test failover regularly; an untested standby is a guess, not a plan.