Explore / Backend system design

Design a Distributed Job Scheduler

Overview

Design a job scheduler that every team in a company can use: "send this reminder email in 3 days", "run the billing job at 02:00 every day in each customer's time zone", "retry this webhook in 5 minutes", "rebuild the search index every hour". Think of a shared, scalable version of cron, like Dropbox's async task framework, Kubernetes CronJobs or Temporal schedules.

The interviewer wants to see three things. First, finding due work efficiently among hundreds of millions of future jobs without scanning them all. Second, ownership under failure: a worker can freeze for 40 seconds and come back believing it still owns a job that someone else has already restarted. Third, the honest answer to "will my job run exactly once?" Write your answer in the Write tab and sketch the architecture in the Diagram tab.

Requirements

Functional

  • Schedule a one-time job at a time or after a delay, and recurring jobs with a cron expression and a time zone.
  • A job runs a registered handler with a payload: a function in a worker fleet, an HTTP callback or a message on a queue.
  • Cancel and update jobs; pause and resume recurring ones.
  • Retries with backoff and a maximum number of attempts; failed jobs end in a dead-letter list.
  • Priorities, so urgent jobs run before bulk ones.
  • Show the history of each job's runs: start, end, attempt, result.

Non-functional

  • Never lose a job that was accepted.
  • On time: 95% of jobs start within a few seconds of their scheduled time.
  • No overlapping runs of the same job unless the owner allows it.
  • Scale: hundreds of millions of scheduled jobs, thousands starting per second, large spikes at round times.
  • Highly available for scheduling requests; a crashed node delays jobs by seconds, not hours.

Estimates

Assume 10 million recurring job definitions and 100 million job runs per day in total, an average run time of 30 seconds, and that 3 million of the runs are scheduled at exactly 00:00 UTC. Work out:

  • Average start rate, and the rate if the midnight jobs had to start within 10 seconds.
  • How many runs are executing at the same time on average.
  • Storage for run history kept 30 days.
  • Whether a single database can hold the index of future runs.

Hints

  • You have 200 million future runs. How do you find the ones due in the next second without scanning everything?
  • A worker takes a job, then stops responding. When should someone else run it, and what if the first worker wakes up?
  • What should happen if last night's 02:00 job is still running when tonight's 02:00 arrives?
  • The scheduler was down from 01:50 to 02:10. Should the 02:00 job run when it comes back? Should 20 one-minute jobs all run at once?
  • Can the scheduler promise a job runs exactly once? If not, what should it ask of the job's code?

Follow-ups

  • How do you run a job "at 02:00 local time" for customers in every time zone, including daylight-saving changes?
  • How would you support job dependencies (run B after A succeeds)?
  • One team schedules 50 million jobs for 9:00 tomorrow. What protects other teams?
  • How do you let a job run for six hours, safely?
  • How would you scale the design 10× without a bigger database?

Write your answer step by step and compare it with the reference solution on GrindPrep.