KatInterview

Building a Task Scheduler for Millions of Jobs

System DesignModel answer
HardModel answerSystem Designdistributed-systemsscalabilityfault-tolerance

Last updated

Design a system that persists and triggers jobs at specified times, handling millions of scheduled tasks and thousands of executions per second.

You need to architect a task scheduling platform that executes work at predetermined times or on repeating intervals.

What the System Must Do

Your scheduler should support:

  • Delayed execution: tasks that run once at a future timestamp
  • Repeating schedules: tasks that fire on cron-style patterns (hourly, daily, custom expressions)
  • Durability: tasks survive restarts and failures
  • Timing accuracy: tasks fire at or shortly after their scheduled moment
  • Scale: accommodate tens of millions of active tasks with peak execution rates around 10–20k/second

What "Good" Looks Like

  • Delivery: every task fires at least once; missing a scheduled run is unacceptable
  • Latency: p99 delay between scheduled time and actual trigger under 2 seconds
  • Uptime: individual server failures don't stop the system

What to Provide

  1. Overall architecture and component responsibilities
  2. API surface for creating, modifying, and canceling tasks
  3. Data modeling: what you store and how you query it efficiently
  4. The "hot path" — how you find and fire what's due right now at high throughput
  5. Failure scenarios: node crashes, duplicate triggers, slow workers

Assume tasks are delivered as messages (HTTP callbacks, queue entries, function invocations). Your scheduler doesn't execute user code directly.

Hints

Hint 1

The core bottleneck is 'give me everything due in the next N seconds' — design your index to make that query fast and horizontally scalable.

Hint 2

Partition your timeline into buckets and shards to avoid a single hot spot when thousands of tasks share the same minute.

Hint 3

Use deterministic identifiers for execution attempts so you can recognize and skip duplicate fires after a crash.