Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 23

Design a distributed job scheduler

Advanced · 40 min · Scheduling & coordination

Teams across a company register background work with a shared scheduler: "rebuild the search index every night at 02:00 Berlin time", "expire this trial in 14 days", "retry this webhook in 30 seconds". They want to register a job once and trust that it runs on time even when individual machines crash, and they want to see what ran and what failed.

Requirements

  • Create, update, pause and cancel jobs with a cron expression and time zone, or a single run time.
  • Start each due run on a worker, retrying failures with backoff up to a configured number of attempts.
  • Let a job declare that it must not run concurrently with itself, and what to do about runs missed during an outage.
  • Show each job's run history: scheduled time, start, end, attempt count and outcome.

Constraints and assumptions

  • 10 million scheduled jobs, mostly one-off; 50,000 recurring jobs.
  • About 30 million runs a day, but up to 20,000 runs become due in the same second at the top of the minute and hour.
  • A run should start within 5 seconds of its scheduled time at p99.
  • Runs last from a second to an hour. Execution is at least once, and job handlers are expected to be idempotent.
  • A schedule that was accepted must survive the loss of any machine or one availability zone.

Out of scope for the first sketch

Workflows with dependencies between jobs · Placing containers on machines (bin packing) · Per-team billing

Draw your design

Rough math and notes

Done on paper? Compare with the worked approaches