Before you start. This series builds a small distributed job scheduler, a program whose only task is to fire off other jobs: a nightly backup, an hourly report, on a repeating schedule, without missing one and without running it twice. So far, our small scheduler can check a list of jobs against the clock and run whichever ones are due. It computes each job’s next run as a fixed point in time rather than “five minutes from now,” which is what stops the schedule from creeping late. And when a job runs longer than the gap between its own runs, it already has three answers to choose from: skip that run, hold it until the current one finishes, or start it anyway alongside the one still going. All three live in one list, inside the memory of one running program, and that is exactly what breaks next.
Lesson 63 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.
Or start free: a free account opens lessons 2 and 3 of every track.
In this lesson
Airbnb, 2014: a schedule with no memory of its own
The fix: write it down
Restart: open the store and pick up where you left off
Away for a week: run-once, backfill, or skip the past
Two workers, one job: a claim, not a glance
The circle has to expire: the lease
The worker that answers too late: at-least-once, honestly
The job row
What’s due is a range query, not a scan
Catch-up, in one statement
The claim, and why it has to be a write
The lease, spelled out
The code that makes the ghost happen
What “exactly once” actually means
The shortcuts this build took
Terms it explains: store, Skip the past entirely, backfill, claim, lease, at-least-once, heartbeats, not, worker-1 dies here, twice, skipped, idempotency key, fencing token, write, Too short, Too long, heartbeat, before, at-most-once, effect, the store's own row, after.