Achieving high availability
medium 30 minHigh availability is built from four pillars: spare copies of everything (redundancy), a way to switch to them (failover), a way to share work between them (load balancing), and a way to notice failures fast (monitoring).
See it run
Find what has no spare, add one, share the work, notice failures, switch, and avoid the traps on the way.
Operations
Remove single points
Start with one of everything and ask of each box: what if it dies now?
Step 1 of 6
One of each
Two single points of failure
One app and one database. Either of them can stop everything.
Step 1: One of each
for box in request_path: if users_notice(box.dies()): if box.holds_data: replicate(box, other_zone) else: run_two(box, other_zone)- Users notice
- Less each step
- Price
- More machines
- Two of 99%
- 99.99% if independent
Do not forget the boxes nobody draws: DNS, certificates, secrets and the payment provider.
In the real world
The same achieving high availability doing real jobs. Pick one and step through it.
Two copies, a broken link, and why a third vote helps.
Step 1 of 4
Two copies
One writer
A is the primary, B copies every change.
Step 1: Two copies
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Both copies in one place
criticalOne rack or one zone takes the original and the spare together.
Wrongrun(app, zone="a", copies=2)Rightrun(app, zones=["a", "b"], copies=2)Promoting without fencing
criticalA primary that was only slow comes back and writes. Two writers damage the data.
Wrongif not ping(primary): promote(standby)Rightif missed_by_majority(primary, 3): fence(primary) promote(standby)Deep health checks in the balancer
majorA shared dependency marks every server unhealthy at once.
Wrongdef health(): return db.ok() and cache.ok()Rightdef health(): # for the balancer return process_can_serve()def deep_health(): # for dashboards return {"db": db.ok(), "cache": cache.ok()}Retrying everything
majorA payment that timed out may have worked. Repeating it charges twice.
Wrongretry(lambda: charge(card))Rightretry(lambda: charge(card, idempotency_key=order_id))
Interview tips
How to explain it
- No box may exist only once.
- Spare, switch, share, watch.
- Say how many seconds the switch takes.
Memory trick: HALF
- Health checks: monitor all the time.
- Active redundancy: several instances.
- Load balancing and Failover automation.
Good defaults
- Stateless apps active-active in two or three zones.
- Database with a standby and automatic failover.
- Check every 5 s, 3 down, 2 up.
Watch out for
- Shared causes: a release, a certificate, a zone.
- Servers with no room for a failed neighbour.
- Failover that was never tested.