KatInterview

Build a Multi-Step Job Execution Engine with Dependency Management

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsorchestrationstate-machines

Last updated

Design a system that executes jobs composed of dependent tasks, managing state, handling failures, and coordinating parallel work across distributed workers.

You need to design an execution engine for multi-step jobs. Users create job templates that define multiple tasks and their dependencies, then launch executions of those templates. The system must run each task in dependency order, maintain execution state, recover from failures, and provide visibility into progress.

Your design should address:

  • Data modeling: How you represent job templates, execution instances, and individual task states
  • Execution coordination: How tasks become ready to run, get assigned to workers, and report completion
  • Reliability: Handling worker crashes, task failures, retries, and ensuring progress
  • Scalability: Supporting many concurrent job executions and distributing work efficiently
  • Multi-tenancy: Preventing one team's workload from starving another's

Before designing, clarify:

  • What types of tasks does the system execute? (API calls, containers, scripts, etc.)
  • How are executions triggered? (Manual API requests, schedules, external events)
  • Expected scale: number of job templates, concurrent executions, tasks per job, and task duration
  • Dependency patterns: strictly sequential, parallel fan-out/fan-in, or arbitrary DAGs?
  • Failure handling requirements: automatic retries, timeouts, manual intervention, rollback logic
  • Multi-tenancy needs: isolation level, priority guarantees, resource quotas

Hints

Hint 1

Model job executions and tasks as separate entities with explicit state transitions

Hint 2

Use a durable queue or database to coordinate which tasks are ready to execute

Hint 3

Design for at-least-once execution semantics and make task implementations idempotent