KatInterview

Build a Workflow Engine with an AI Coding Assistant

System DesignModel answer
MediumModel answerSystem Designworkflow-engineai-assisted-codinggraph-execution

Last updated

Design, implement, and verify a two-endpoint workflow service—create and execute—in 45 minutes while demonstrating a disciplined plan-then-code loop with an AI assistant.

The Task

You have 45 minutes and access to an AI coding assistant. Use it to build a small backend service that manages and runs workflows. The service needs exactly two endpoints:

  • POST /workflows — accept a workflow definition, validate it, persist it, and return a unique identifier.
  • POST /workflows/:id/run — load a stored workflow, execute it against a provided input, and return a per-step summary of what happened.

The interviewer is watching how you collaborate with the assistant, not counting lines of code. The goal is to show a deliberate plan-before-code habit, critical review of whatever the assistant produces, and a working tested slice by the end of the session.


What is a Workflow?

The prompt leaves this open on purpose. A reasonable starting definition:

  • A workflow has a name and an ordered-or-unordered set of steps.
  • Each step has a unique ID, names one action from a fixed server-side registry, carries its own static parameters, and may declare dependencies on other step IDs.
  • When a workflow runs, each step receives its static parameters plus the outputs of whatever steps it depends on.
  • The run returns a result object that records the final status and output of every step.

You may simplify or extend this — but whatever you choose, state it explicitly before touching any code.


Clarifying Questions to Settle Before Coding

Think through (and ask the interviewer about) these before writing a plan:

  1. Are dependencies a flat list or a full DAG? Can independent steps run in parallel, or is serial topological order fine for this session?
  2. What actions can a step call — only a hard-coded in-process registry, or arbitrary HTTP endpoints?
  3. Does POST /workflows/:id/run block until the run finishes, or does it return a run ID for the client to poll?
  4. When a step fails, does the entire run abort, or do steps that don't depend on the failed step still execute?
  5. Does state need to survive a process restart, or is in-memory storage acceptable?
  6. Can a stored workflow be updated after creation? If so, which version does an in-flight run use?

What Each Part Should Demonstrate

Part 1 — Plan with the assistant

Produce a short written plan before generating any code. It should cover:

  • The assumptions you chose and any scope you deliberately cut to fit the time box.
  • A concrete JSON schema for a workflow definition and for both request/response bodies, including what error responses look like.
  • A list of tests you intend to write, named before implementation begins.
  • Evidence that you steered the assistant rather than accepted its first output wholesale.

Part 2 — Implement the two endpoints

Build POST /workflows and POST /workflows/:id/run. Requirements:

  • Creation-time validation: reject definitions that reference unknown actions, contain duplicate step IDs, point to non-existent dependency steps, or contain a dependency cycle.
  • Execution: run steps in an order that satisfies all dependencies; pass each step the outputs of its declared predecessors; catch step-level errors without crashing the service.
  • HTTP layer: return appropriate status codes (201, 400, 404, 500); keep routing code thin and separate from core logic.

Part 3 — Verify correctness

Demonstrate that the service behaves correctly by:

  • Running tests that cover the happy path, out-of-order step definitions, each category of invalid definition, and a step that throws at runtime.
  • Diagnosing any test failures rather than commenting them out or patching without understanding.
  • Reviewing the assistant's generated code for hallucinated library calls, silently swallowed errors, and branches that have no test coverage.

Hints

Hint 1

Start by writing your test list before asking the assistant for any code. Naming the tests first forces you to pin down the exact behavior you want — cycle detection, failure propagation, out-of-order deps — and gives you a checklist to drive the implementation conversation instead of reacting to whatever the assistant generates first.

Hint 2

Separate the problem into three layers before coding: (1) a pure validator that checks the workflow definition in isolation, (2) a pure executor that takes a validated workflow and an input map and returns a result map, and (3) a thin HTTP shell that wires them together. Ask the assistant to implement each layer independently so you can test the hard logic without spinning up a server.

Hint 3

After the assistant writes the dependency-ordering logic, ask it to walk you through the algorithm on a concrete example: three steps where C depends on B and B depends on A, all defined in reverse order. If it can't narrate the traversal correctly, the code probably has a bug you should find before running tests.