KatInterview

Building a Durable Workflow Orchestrator Across Microservices

System DesignModel answer
HardModel answerSystem Designworkflow-orchestrationdistributed-systemsidempotency

Last updated

Design a fault-tolerant engine that runs multi-step service workflows with ordering, retries, compensation, and exactly-once side effects.

Context

You are designing a workflow orchestration engine that coordinates long-running business processes spanning several independent services. Typical processes include fulfilling a purchase, onboarding a seller, and issuing driver payouts. Each process is a chain of steps that touch different downstream services (payments, inventory, dispatch, notifications), and steps may branch, run in parallel, and depend on each other.

The engine must keep these processes moving correctly even when engine hosts crash, networks partition, or workers die mid-step. The downstream services include non-idempotent real-world actions (charging a card, sending a notification), so duplicate execution is not acceptable.

Requirements

Functional

  • Define workflows as DAGs or state machines with branching, parallelism, dependencies, and typed inputs/outputs.
  • Dispatch individual steps to separate worker services over queues or RPC.
  • Per-step retry policy with exponential backoff, timeouts, and optional compensation (rollback) steps that run when a workflow hits a terminal failure.
  • Guarantee that critical side effects are never duplicated.
  • Provide APIs to inspect a workflow's progress, per-step history, and to pause, resume, cancel, or replay a run.

Non-functional

  • Durability: no committed state is lost when an engine node or worker crashes.
  • Scale: ~50,000 concurrent workflow runs, peak ~10,000 state transitions per second.
  • Latency: handoff between dependent steps under 100ms at p99.
  • Language-agnostic workers: any service can register for a task type.

What to Cover

  1. Overall component architecture and their interactions.
  2. Data model and how execution state is persisted.
  3. How workers are dispatched to, monitored, and how unrecoverable steps are handled.
  4. Recovery procedure for orchestrator crashes and worker crashes.
  5. The idempotency and leasing scheme that makes side effects safe.