KatInterview

Design a Fault-Tolerant Orchestration Engine for ML Pipelines

System DesignModel answer
HardModel answerSystem Designsystem-designmachine-learningdistributed-systems

Last updated

Design a multi-tenant ML workflow scheduler that handles versioned DAGs, heterogeneous compute routing, data quality enforcement, and reproducible lineage tracking.

Context

A growing ML platform team runs hundreds of pipelines every day — ingesting raw data, computing features, training models, and promoting artifacts to production. Today those pipelines are glued together with cron jobs and ad-hoc scripts. The team needs a purpose-built orchestration service to replace that patchwork.

You are asked to design that service from scratch. Think of it as an ML-aware workflow engine: something that knows about GPU pools, terabyte-scale datasets, data contracts, and reproducibility — not just task dependencies.

Functional Requirements

  • Versioned workflow definitions. Pipelines are defined in code. Each version captures task logic, dependency graph, container images, and environment configuration immutably.
  • Reliable task execution. The engine must survive worker crashes. It needs durable state, configurable retry behavior, and a mechanism to detect and recover stalled tasks.
  • Heterogeneous compute. Tasks declare their resource needs (CPU, high-memory, GPU). The scheduler routes each task to the appropriate pool.
  • Data quality enforcement. Before any dataset becomes visible to downstream consumers, automated checks must pass: schema consistency, null-rate limits, and statistical distribution tests. Publication must be atomic — no consumer should ever observe a partially written or unvalidated dataset.
  • Lineage and backfill. Every run records what inputs it consumed and what outputs it produced (by content hash), along with the exact code version and parameters used. Historical re-runs must not reprocess partitions that already have valid results.
  • Fair resource sharing. No single team or pipeline should be able to monopolize shared compute pools.

Scale Assumptions

  • 500 registered pipelines; ~10,000 DAG runs per day; ~20 tasks per run → roughly 200,000 task executions per day.
  • Peak concurrency around 3,000 simultaneously running tasks.
  • Dataset artifacts range from 1 GB to 20 TB; the orchestrator never moves data — it tracks URIs and hashes.
  • Task dispatch must happen within 5 seconds of all upstream dependencies completing.

What to Cover in Your Answer

  1. Architecture overview — identify the major components, what each one owns, and how they communicate.
  2. Task state machine and crash recovery — how transitions are made durable and how the system handles zombie workers without duplicate commits.
  3. Atomic dataset publication and quality gates — the exact sequence from task output to consumer-visible dataset, including how concurrent writers are handled.
  4. Fair-share scheduling — how the engine prevents resource starvation across tenants and task types.
  5. Lineage and reproducible backfills — the data model and lookup strategy for skipping already-valid partitions.

Address trade-offs throughout. Where you make a design choice, briefly explain what you gave up.

Hints

Hint 1

Start by converting the scale numbers into concrete rates — tasks per second, state writes per second, heartbeats per second. Those numbers determine whether a single Postgres instance is viable or whether you need something heavier, and they give you something concrete to defend in the interview.

Hint 2

For crash recovery, the key insight is separating 'duplicate execution' (which you cannot fully prevent across a network partition) from 'duplicate commit' (which you can prevent with a lease epoch and a compare-and-swap on the final state transition). Be explicit about which guarantee you are actually providing.

Hint 3

Atomic dataset publication is essentially a pointer swap. Model it as an alias record with an optimistic-concurrency revision counter. The quality gate runs as a first-class task in the DAG, not as an out-of-band side process — that way it participates in retry, lineage, and observability like any other task.