KatInterview

Distributed Job Scheduler with Pause and Resume

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsschedulingfault-tolerance

Last updated

Build a fault-tolerant scheduler that triggers recurring tasks on cron-like intervals with pause/resume control and multi-instance coordination.

You need to architect a recurring task scheduler that reliably triggers jobs based on time-based rules similar to cron expressions. The execution infrastructure has sufficient capacity, so your design should concentrate on correctness, coordination, and durability rather than autoscaling compute resources.

Your system must handle:

  • Time-based recurring tasks using cron-style syntax (for example, 0 */6 * * * means every 6 hours)
  • pause(job_id) — prevent future scheduled triggers, but allow currently-executing instances to complete
  • resume(job_id) — re-enable future scheduled triggers

Provide a complete architectural design that includes: (a) the external API surface, (b) how you model persistent state, (c) the scheduling loop that identifies and fires ready tasks, (d) how pause/resume work correctly even when racing with the scheduler, (e) how multiple scheduler instances coexist safely, and (f) how the system recovers from crashes without losing or silently dropping triggers.

Constraints & Assumptions

  • Execution capacity is not a bottleneck — never constrain your design based on worker availability. The complexity is in scheduling correctness, not task execution.
  • Scale target (or state your own): approximately $10^6$ task definitions; peak load of tens of thousands of tasks becoming ready in the same minute. Most schedules use minute-level granularity.
  • Correctness requirements: every ready, active task must eventually trigger (no silent drops), with at-least-once semantics and best effort to avoid duplicates. Don't assume tasks are inherently idempotent.
  • High availability: the scheduler continues operating through single-instance failures; multiple scheduler instances run concurrently.
  • The actual task implementation is a black box (HTTP callback, message payload, etc.); you're designing the scheduling infrastructure, not the task logic.

Important Questions to Consider

  • What time precision do we need — minute-level only, or sub-second? Should we handle multiple timezones and DST transitions, or is UTC sufficient?
  • When resuming after a long pause or outage, should we catch up on missed triggers or simply continue from the next future occurrence?
  • Is at-least-once delivery sufficient (assuming task-side deduplication) or do certain task types require at-most-once guarantees?
  • What's the usage pattern: many infrequent tasks or few high-frequency tasks? What's the peak per-minute fan-out?
  • How do tasks execute — via internal queue, HTTP webhook, container orchestration? What retry and timeout behavior is expected?
  • How long should execution history and audit trails be preserved?

Hints

Hint 1

Think about what fields in your task metadata enable safe claiming by competing scheduler instances

Hint 2

Consider how you'd make the query for 'tasks ready to fire' efficient across millions of task definitions

Hint 3

What durable record proves a task was scheduled, even if the scheduler crashes immediately after?