KatInterview

Design a Scalable Distributed Task Processing Engine

System DesignModel answer
HardModel answerSystem Designsystem-designdistributed-systemsfault-tolerance

Last updated

Design an architecture for a multi-tenant distributed task execution platform handling millions of parallel jobs, emphasizing fault tolerance, scheduling, leases, and idempotency.

Architect a distributed task processing engine capable of executing large-scale batch jobs composed of independent, heterogeneous tasks across a multi-tenant compute cluster.

Requirements & Context

  • Input & Execution Model: Users submit jobs containing anywhere from a few tasks up to tens of millions of independent tasks (e.g., video processing, ML feature extraction). Tasks take anywhere from hundreds of milliseconds to several minutes to run.
  • Core Functionality: The system must support task scheduling, progress querying, job cancellation, priorities, retries with backoff, and task result aggregation.
  • Fault Tolerance & Guarantees: Compute instances can crash, experience network partitions, or suffer from long garbage collection pauses. System state must remain consistent, preventing orphan tasks, infinite loops, and duplicate side effects where possible.

Expected Coverages

  1. API & Data Model: Design the public endpoints and underlying persistence schemes (job/task representations and queue structures).
  2. Scheduling Architecture: Explain worker discovery, work distribution (pull vs. push), task partitioning, and tenant fairness/prioritization.
  3. Leasing & Execution Coordination: Describe how task ownership, heartbeats, fencing tokens, and timeout reclaims operate safely.
  4. Fault Recovery & Idempotency: Detail retry strategies, error classification, poison task/host handling, and achieving at-least-once or effectively-once execution semantics.
  5. State Aggregation & Scalability: Explain how the system updates job progress counters without creating hot spots, auto-scales worker capacity, and prevents downstream system overload (backpressure).

Hints

Hint 1

Differentiate between job submission (generating metadata) and task ingestion (expanding millions of tasks into execution queues) to avoid blowing up memory or API latency.

Hint 2

Consider how to handle zombie workers—workers that lose network connectivity but continue processing locally—to avoid split-brain side effects when a task is re-assigned.

Hint 3

For high-throughput jobs with millions of tasks, updating a single job record in a database on every task completion will cause extreme write contention. How can you shard counters?