KatInterview

Architecting a Distributed Asynchronous Job Execution System

System DesignModel answer
MediumModel answerSystem Designsystem-designdistributed-systemsqueues

Last updated

Design a scalable, fault-tolerant job scheduler that manages delayed execution, recurring tasks, worker leasing, and failure recovery with at-least-once delivery.

Design an asynchronous background job processing system capable of executing tasks at a designated future time or on a recurring schedule.

Requirements & Functional Scope

  1. Task Lifecycle & Types: Support one-time delayed tasks (e.g., send an email in 2 hours) and recurring CRON-like tasks (e.g., generate a daily analytics report).
  2. Execution Guarantees: Provide at-least-once delivery. Tasks must not be dropped due to application crashes or network partitions. Workers acquire tasks via dynamic leases to handle execution timeouts.
  3. Task Operations: Support task scheduling, cancellation, retry strategies (with exponential backoff), and tracking job status.
  4. Scalability & Performance: Assume a target scale of 10,000 tasks per second with execution latency within seconds of the scheduled run time.

Deliverables

Provide a high-level architecture diagram (ASCII/Text), data model, core workflow mechanisms (polling vs. pushing, handling concurrency and race conditions), worker lease/heartbeat mechanisms, and failure handling strategies.

Hints

Hint 1

Consider how to efficiently index tasks by run time to avoid full-table scans when searching for pending execution targets.

Hint 2

Think about how multiple worker nodes prevent claiming the same job simultaneously without relying on heavy distributed locking overhead.

Hint 3

Distinguish between one-off scheduled jobs and recurring tasks when updating state post-execution.