KatInterview

Build a Task Scheduler That Grows from Startup to 100x Scale

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsschedulingfault-tolerance

Last updated

Design a job scheduling system supporting one-time and recurring tasks, retries, and observability, then evolve it to handle 100x traffic growth.

You're building a task scheduling platform that lets users and services schedule work to run at specific times or on recurring intervals.

Your system must support:

  • One-time tasks (fire once at a specific timestamp) and recurring tasks (cron-style expressions with timezone support)
  • Execution guarantees: tasks should fire within a few seconds of their scheduled time and persist durably once accepted
  • Retry logic for tasks that fail, with configurable backoff policies
  • Cancellation and modification of scheduled tasks before they run
  • State tracking through the task lifecycle: waiting, dispatched, executing, completed, failed
  • Operational visibility so engineers can monitor execution health and debug failures

Your challenge has two phases:

Phase 1: Design the initial architecture for a small company handling roughly 1 million scheduled tasks with about 50 executions per second on average, spiking to 500/second at peak times (think top-of-the-hour cron clustering).

Phase 2: Explain how you would evolve this design to support 100x growth: 100 million tasks, 5,000 executions/second average, 50,000/second peak.

Address these dimensions:

  1. API surface and core entities
  2. Data schema and how you model task definitions versus individual firings
  3. Execution mechanism: how tasks get picked up and run safely
  4. Correctness concerns: preventing duplicate runs, handling retries, achieving idempotency
  5. Fault tolerance: what happens when scheduler nodes, workers, or the database fail
  6. Observability: what metrics and logs operators need
  7. The migration path from phase 1 to phase 2, including which bottlenecks emerge and how you address them

Be concrete about technology choices, query patterns, and the trade-offs you're making at each scale tier.

Hints

Hint 1

Separate the task definition from each individual execution—they have different lifecycles and access patterns

Hint 2

Use database-level primitives like SELECT FOR UPDATE SKIP LOCKED to claim work without contention in the initial design

Hint 3

Consider how at-least-once delivery differs from exactly-once, and where idempotency keys fit into your execution model