LESSON 72 / 215·2 min readIntermediate

State machines, DAGs, and event-driven workflows

Should knowConcept lesson
01 Understand02 Recall03 Prepare

Words made simple

A few useful meanings before you read the explanation.

State
The data describing where a workflow is now, what it already knows, and what still needs to happen.
AI
Software techniques for tasks such as recognizing patterns, understanding language or generating content.
Embedding
A list of numbers that represents the meaning of some content. Similar meanings can produce nearby lists of numbers.
More words from this lesson
Schema
A description of the fields and value types that data should contain. It helps check that an answer has the expected shape.
Agent
An application that uses a model to choose its next action within defined limits. It can use tools and continue through several steps.
Persistence
Saving information so it remains available after a request ends or a process restarts.
Durable
Able to retain progress and recover across interruptions. Durable workflows require appropriate storage and retry behavior.
HTTP
The request-and-response protocol used on the web. HTTPS adds encryption to protect information in transit.

🟠 SHOULD KNOW · These are backend engineering concepts applied to AI workloads.

Overview

  • A state machine models valid states and transitions.
  • A DAG, directed acyclic graph, models dependencies without loops.
  • Event-driven workflows react to events such as document.uploaded or review.approved instead of doing all work inside one HTTP request.

Why this matters

AI pipelines often involve dependent steps, parallel work, and user events that arrive later.

An everyday example

A claim moves through stages, document processing has dependencies, and an approval message triggers the next step.

A technical example

Parse and OCR jobs finish before embeddings are generated; approval is an external event correlated to a draft ID.

How it works

  1. Persist request/job
  2. Emit event
  3. Worker validates dependency/state
  4. Execute step
  5. Record outcome
  6. Emit next event.

Architecture and flow

Durable event → state/dependency check → worker → persisted result → next event.

The insurance assistant example

Claim intake launches document analysis and fraud checks independently, then a review step waits for both required outcomes.

When to use it

Background pipelines and multi-step processes with clear dependencies.

When to avoid it

Avoid assuming every graph is a DAG: agent loops are cyclic. Do not build event infrastructure for a trivial synchronous lookup.

Interview answer

“I use state machines for lifecycle rules, DAGs for acyclic dependencies, and events for decoupled asynchronous progress.”

Benefits, trade-offs, and production considerations

  • Define event schemas, correlation IDs, ordering assumptions, deduplication, and ownership.
  • Queue delivery is commonly at least once; consumers must tolerate repeats.
PAUSE & RECALL

Can you explain it without the notes?

State machines, DAGs, and event-driven workflows

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

A state machine models valid states and transitions. A DAG, directed acyclic graph, models dependencies without loops. Event-driven workflows react to events such as document.uploaded or review.approved instead of doing all work inside one HTTP request.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Long-running workflows, retries, timeouts, and schedules

Adapted from 13_AI.MD · “State machines, DAGs, and event-driven workflows”. Examples are study fragments; framework behavior can depend on your version.