KatInterview

Build a Scalable Task Execution System

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsschedulingfault-tolerance

Last updated

Design a fault-tolerant background task scheduler supporting one-time and recurring jobs with at-least-once guarantees at scale.

You're building a background task execution platform that lets clients schedule work to run at specific times or on repeating schedules.

Requirements

Your system must handle:

Task Types:

  • Tasks that run once at a given timestamp
  • Tasks that repeat on a schedule (similar to cron expressions like "daily at 3 AM" or "every Monday")

Core Functionality:

  • Clients can submit new tasks, cancel existing ones, and query execution history
  • Every task must execute at least once (duplicate runs are acceptable if they're idempotent)
  • Support task priorities—higher priority work should be picked up first when multiple tasks are ready
  • Recover gracefully when execution nodes fail mid-task

Scale & Availability:

  • Handle around 100,000 task executions per minute
  • Keep submission and query latency under 100ms
  • Eliminate single points of failure

What to provide

  1. Architecture overview: main components and how they communicate
  2. Data model: schemas for storing task definitions and execution records
  3. Scheduling mechanism: how tasks become ready and get dispatched to workers
  4. Failure handling: strategies for retries, dead-letter processing, and preventing lost work

Focus on the distributed systems aspects—assume task handlers are pre-registered functions identified by name.

Hints

Hint 1

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

Hint 2

Use database-level concurrency primitives like SELECT FOR UPDATE SKIP LOCKED or optimistic locking to safely claim ready tasks

Hint 3

A timing wheel or sorted set can reduce polling load, but keep the database as the source of truth for durability