AlgoViz

Achieving high availability

medium 30 min

High 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

Our systemUsersAPI 1zone APrimaryzone A

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

replicationDatabase AprimaryDatabase Bstandby

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

    critical

    One rack or one zone takes the original and the spare together.

    Wrong
    run(app, zone="a", copies=2)
    Right
    run(app, zones=["a", "b"], copies=2)
  • Promoting without fencing

    critical

    A primary that was only slow comes back and writes. Two writers damage the data.

    Wrong
    if not ping(primary):    promote(standby)
    Right
    if missed_by_majority(primary, 3):    fence(primary)    promote(standby)
  • Deep health checks in the balancer

    major

    A shared dependency marks every server unhealthy at once.

    Wrong
    def health():    return db.ok() and cache.ok()
    Right
    def health():          # for the balancer    return process_can_serve()def deep_health():     # for dashboards    return {"db": db.ok(), "cache": cache.ok()}
  • Retrying everything

    major

    A payment that timed out may have worked. Repeating it charges twice.

    Wrong
    retry(lambda: charge(card))
    Right
    retry(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.