System design · 11 of 16
Mid
Senior
- Monitoring and alerting for 100 servicesSRE · Platform · DevOps
- Secrets management platformDevOps · Platform · SRE
- Multi-region active-active serviceSRE · Platform
- Distributed job scheduler (cron at scale)SRE · Platform
- Internal developer platform (IDP)Platform
- Multi-tenant Kubernetes platformPlatform · DevOps · SRE
- GitOps for a fleet of 100 clustersPlatform · DevOps
- ML training platform and feature storeMLOps · Platform
- LLM inference platformMLOps · Platform · SRE
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 →
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
- Teams create jobs through the scheduler API; definitions go to a job store with an index on
next_run_at. - 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.
- Every second, a leader selects due jobs for its shards, puts a run message on the work queue, and moves
next_run_atforward in the same transaction. - Workers pull from the queue, run the job with a timeout, record the result in run history and acknowledge the message.
- 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
| Decision | Choice | Why |
|---|---|---|
| Who decides a job is due | sharded schedulers with leases | scales out, no double scheduling |
| Queue between scheduling and running | yes (SQS, Kafka, Redis streams) | absorbs spikes like every job at midnight |
| Duplicates | idempotency keys per run | a retry or failover can't double-charge |
| Thundering herd at :00 | add small random delay (jitter) if the job allows | smooths 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)
| Item | Assumption | Result |
|---|---|---|
| Job definitions | 5 million | indexed by next_run_at |
| Midnight spike | 20,000 runs in the first minute | ~333 runs/s |
| Average run time | 30 seconds | workers needed = 333/s × 30 s = ~10,000 at once |
| With jitter | spread starts over 10 minutes | ~1,000 workers: 10x cheaper |
High availability and disaster recovery
| Target | Number | How it is met |
|---|---|---|
| Availability | 99.95% | 3+ scheduler instances, a replicated queue, Multi-AZ database |
| Scheduler leader dies | jobs resume in ~10-15 s | leases expire after 10 s and another instance takes the shard |
| Worker dies mid-job | job retried | message reappears after its visibility timeout |
| Region fails | RTO 15 min, RPO 5 min | warm standby region with a database replica |
| Runs missed during an outage | handled on purpose | each 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.