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 07: The Hard Part, Time

The Hard Part - Time
The Hard Part, Time · Open board

From Scratch · Distributed Scheduler.

Before you start. This lesson is part of a build that makes a small distributed job scheduler: a program that fires jobs at the right moment, on the right machine, even when a machine crashes mid-run. Six earlier stages already gave it a lot. It can tell which job is due next without scanning the whole list. It survives a crash, because every job lives in a database instead of only in memory. Several machines run the scheduler, but only one of them, the leader, decides which jobs fire. It stays leader by holding a lease, a permission that runs out unless it keeps renewing it. The leader does not run the jobs itself. It drops each one into a queue, a waiting line that other machines take work from. And every new lease comes with a bigger number, so the database can refuse a write from an old leader that has not noticed it was replaced. All five of those were built on one thing nobody checked: that the clock telling them the time is telling the truth.

Lesson 68 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

  • 30 June 2012: the extra second that grounded a check-in counter
  • The habit every stage shared, and never said out loud
  • A wall clock and a stopwatch are not the same instrument
  • The night 2:30am does not happen, and the night it happens twice
  • Lying smoothly: how the world hid the next one

Terms it explains: leap second, wall clock, monotonic clock, Leader Election, daylight saving, monotonic, wall-clock, NTP, Slewing, Stepping, not, Catch-up, Overlap, Google, "Leap Smear", Go's `time` package documentation, Distributed Scheduler.

Related papers

Review From Scratch