Skip to content
$ lynuxpro
← All system designs

SENIOR · 13 MIN · SRE · PLATFORM

Distributed job scheduler (cron at scale)

Run millions of scheduled jobs exactly when due, once, with leader election, a work queue, retries and a dead-letter queue.

Peak load
333 runs/s at midnight
Availability target
99.95%
RTO: back up within
15 min
RPO: data you can lose
5 min

← Swipe sideways to see the whole diagram →

ServiceData storeInfrastructureQueue / streamasync / background

The question

"Design a service where teams schedule jobs (every 5 minutes, daily at 2 a.m., once next Tuesday) and the jobs run reliably at scale."

Requirements

  • Millions of job definitions; tens of thousands of runs per minute at peak.
  • Run each job once per schedule, close to on time (within seconds).
  • Retries with backoff, timeouts, and a place for jobs that keep failing.
  • No single point of failure.

How it works

  1. Teams create jobs through the scheduler API; definitions go to a job store with an index on next_run_at.
  2. Scheduler instances each own a set of shards. Each shard has one leader at a time, chosen with leases in etcd or database row locks.
  3. Every second, a leader selects due jobs for its shards, puts a run message on the work queue, and moves next_run_at forward in the same transaction.
  4. Workers pull from the queue, run the job with a timeout, record the result in run history and acknowledge the message.
  5. Failed runs are retried with exponential backoff and jitter; after N tries they go to a dead-letter queue and alert the owner.

Remember it: "exactly once" is very hard. Aim for at-least-once delivery plus idempotent jobs (running twice does no harm).

Key decisions

DecisionChoiceWhy
Who decides a job is duesharded schedulers with leasesscales out, no double scheduling
Queue between scheduling and runningyes (SQS, Kafka, Redis streams)absorbs spikes like every job at midnight
Duplicatesidempotency keys per runa retry or failover can't double-charge
Thundering herd at :00add small random delay (jitter) if the job allowssmooths load

What breaks and how it heals

  • Scheduler leader dies: its lease expires and another instance takes the shard.
  • Worker dies mid-job: the message becomes visible again after its visibility timeout and is retried.
  • Downstream outage: retries back off; circuit breakers stop hammering a dead dependency.

Load and capacity (Little's law)

ItemAssumptionResult
Job definitions5 millionindexed by next_run_at
Midnight spike20,000 runs in the first minute~333 runs/s
Average run time30 secondsworkers needed = 333/s × 30 s = ~10,000 at once
With jitterspread starts over 10 minutes~1,000 workers: 10x cheaper

High availability and disaster recovery

TargetNumberHow it is met
Availability99.95%3+ scheduler instances, a replicated queue, Multi-AZ database
Scheduler leader diesjobs resume in ~10-15 sleases expire after 10 s and another instance takes the shard
Worker dies mid-jobjob retriedmessage reappears after its visibility timeout
Region failsRTO 15 min, RPO 5 minwarm standby region with a database replica
Runs missed during an outagehandled on purposeeach job has a misfire policy: run once now, run all missed, or skip

What interviewers listen for

  • Leader election or sharding to avoid double scheduling.
  • At-least-once plus idempotency instead of promising exactly-once.
  • Retries, backoff, dead-letter queues and handling the midnight spike.