KatInterview

Building a DAG Workflow Engine on Kubernetes

System DesignModel answer
HardModel answerSystem Designkubernetesworkflow-orchestrationdag-scheduling

Last updated

Design a Kubernetes-native system that schedules containerized DAG tasks with dependency ordering, retries, durable state, and multi-tenant isolation.

Context

You are asked to design a service that lets users hand in multi-step computational workflows. Each workflow is a directed acyclic graph (DAG): every node is a containerized batch job, every edge says "this task cannot start until that one has finished successfully." The execution substrate is a Kubernetes cluster.

Walk through the design as you would in an interview: nail down scale, define the user-facing API, pick the storage model, describe how the control plane uses Kubernetes primitives, and then go deep on dependency scheduling, failure recovery, and tenant isolation. Expect follow-up questions about what happens when the orchestrator itself dies mid-run.

What the system must do

  • Accept workflows: a caller posts a JSON (or YAML) DAG; nodes carry an image, command, resource requests, and an optional retry/backoff policy; edges encode dependencies.
  • Schedule correctly: a node launches only once every upstream node has succeeded; downstream nodes of a failed node never run.
  • Handle failures: per-task retry limits with configurable backoff, and the ability to distinguish a user-code failure from an infrastructure failure.
  • Persist state: after a control-plane restart, in-flight workflows resume without losing progress or double-launching work.
  • Serve observability: users can poll status, follow logs live, and see per-attempt history.

Non-functional expectations

  • Thousands of concurrent workflow runs and ~100k live task objects at steady state.
  • Hard logical isolation between tenants (namespaces, quotas, RBAC).
  • Finished runs remain queryable for weeks.

Deliverables

  1. The public API surface (submit, query, cancel, stream, logs).
  2. The architecture: which Kubernetes objects you create, what the controllers watch, and where the source of truth lives.
  3. How dependency resolution and retry scheduling are implemented.
  4. A crash-recovery story for the orchestrator, and how you avoid duplicate pod launches.
  5. Your reasoning on tenant isolation and observability.