Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 09 · From Scratch · Distributed Scheduler · with code: Go · about 26 min to read

Play it as a journeyTutor comes with a plan

Scheduler 04: Leader Election

Leader Election
Leader Election · Open board

From Scratch · Distributed Scheduler. Follows Scheduler 03: Heap and Timing Wheel, which made “what fires next” cheap, and hands off to Scheduler 05: Dispatch Queue.

Before you start. This series builds a small copy of a job scheduler: a program whose whole purpose is to fire other programs at the right moment, the way a phone alarm goes off at 7am with nobody watching the clock by hand. So far, that scheduler runs on one machine, a single computer, and it can already hold thousands of pending jobs while always knowing which one fires next without checking every one of them. This lesson is about what happens the moment you stop trusting that one machine to stay up, and run three of it instead.

Lesson 65 of 117 in From Scratch

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • Three schedulers, and the job that fired three times
  • 1989: a parliament that could never all be in the room
  • The stick you must keep touching
  • Asleep at the podium
  • The room stops listening
  • One atomic compare-and-set
  • Renewal, and the TTL trade
  • Failover, on a logical clock
  • Split-brain, played out
  • The fix: fencing
  • Three rules about the token
  • What fencing does not give you

Terms it explains: Leader election, lease, split-brain, token, Fencing, single atomic operation, etcd, ZooKeeper, Redis, A Postgres row, the zombie's, not, new lease, check the token, sharding the leadership, Delete the fencing check.

Related papers

Review From Scratch