Problem Statement
Design and implement a distributed job scheduler service that:
- Accepts job submissions with a scheduled execution time
- Executes jobs at or near their scheduled time
- Supports job priorities
- Handles worker failures gracefully
- Prevents duplicate execution
- Can be deployed on cloud infrastructure
This is a live coding round — you need to produce working code, not just a whiteboard design.
Requirements
Functional:
- Submit a job (payload, scheduled_time, priority, max_retries)
- Cancel a pending job
- Query job status (pending, running, completed, failed)
- Support recurring/cron-style jobs (bonus)
Non-Functional:
- At-least-once execution guarantee
- Jobs execute within a few seconds of scheduled time
- Horizontally scalable (more workers = more throughput)
- Fault tolerant (worker crash doesn't lose jobs)
What the Interviewer Expects
- Architecture: API server + job queue (Redis/Kafka) + worker pool + persistence (Postgres)
- Job lifecycle: submitted → queued → picked up → running → completed/failed
- Worker failure handling: heartbeat mechanism. If no heartbeat for N seconds, reassign job to another worker.
- Idempotency: each job has a unique ID. Workers check before executing. Prevents double-execution on retries.
- Priority: use a priority queue or sorted set. Higher priority jobs get picked first.
- Scheduling: a "ticker" process that moves jobs from scheduled state to queue when their time arrives.
- Deployment: containerized service, discuss how you'd deploy on Kubernetes with auto-scaling workers.
Follow-ups
- How do you handle job dependencies (job B should only run after job A completes)?
- How do you prevent starvation of low-priority jobs?
- What happens if the scheduler process itself crashes? How do you recover?
- How would you implement rate limiting per tenant in a multi-tenant scheduler?
- How would you add observability — monitoring, alerting, and debugging failed jobs?