High availability and failover

Topic 7 of 8 in Week 2: Scaling, traffic and estimation11 min readIntermediateFree course

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

High availability across availability zones. Users reach the system through DNS and a load balancer that spans both zones. Availability zone A runs App 1 and App 2 and the database primary, which handles reads and writes. Availability zone B runs App 3 and App 4 and a standby replica that takes over on failure. The primary copies every write to the standby in the other zone; if zone A fails, the standby is promoted.

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:

  1. Detect the failure: health checks or heartbeats stop answering for a set time.
  2. 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.
  3. 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.

Exercise

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.

Text
Single points of failure:
-

Highly available version:
-

Still can't survive:

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.