When to reach for it
- Runs take a long time or can fail.
- States and retries must be robustly managed.
- Production demands traceability.
A graph that can be drawn.
Workflows are operated as persistent execution graphs featuring resumability, retries, and state history.
In practiceA document-processing pipeline runs OCR, classification, and archival as nodes in a durable graph, replaying only the failed node after a transient storage error.
The workflow is a graph that is stored outside the process running it. An engine records the result of every node, retries failed nodes by a policy, and can rebuild a run from its history.
1 · Define
2 · Execute
| Node | Attempt | Result |
|---|---|---|
| ocr | 1 | The text of 12 pages, recorded |
| classify | 1 | “Invoice”, recorded |
| archive | 1 | Storage error |
| archive | 2 | After 30 seconds: storage error |
| archive | 3 | After 60 seconds: stored. The run is complete |
WORKFLOW = { # node: (function, depends on, attempts)
"ocr": (run_ocr, [], 1),
"classify": (classify, ["ocr"], 2),
"archive": (archive, ["ocr", "classify"], 3),
}
def execute(run_id, document):
# results of the nodes that already finished
history = load_history(run_id)
for node, (function, needs, attempts) in WORKFLOW.items():
if node in history:
continue # finished before a restart: not run again
inputs = [history[n] for n in needs] or [document]
for attempt in range(1, attempts + 1):
try:
history[node] = function(*inputs)
# recorded before the next node starts
save_history(run_id, history)
break
except TransientError:
if attempt == attempts:
raise
wait(seconds=30 * attempt)
return historyWhen to reach for it
When it backfires
A conditional edge creates an implicit cycle that the DAG validator misses. The workflow loops indefinitely at runtime.
Countermeasure
Run a static cycle check at build time. Reject any graph that contains a back-edge unless it's explicitly declared as a loop.
Every new requirement gets squeezed into the existing DAG shape. The graph becomes a tangled mess of conditional hacks.
Countermeasure
Re-evaluate the DAG topology quarterly. If conditional edges exceed 30% of total edges, consider decomposing into smaller graphs.
Next pattern
Search patterns, frameworks, and pages.