Skip to main content

Static Parallel Steps

View as Markdown

Run a fixed set of distinct Step types at the same time. Use it when each branch has a known job and input type, such as charging a payment and reserving stock for one order.

How it works

In the graph, InitStep returns one movement for WorkA and one for WorkB in a single decision. Dex runs both at the same time, and each completes on its own. Add a join only when a later Step needs their results; see Await Parallel Steps.

Prefer one domain-named Step type per fixed kind of work, even when the branches look alike. The graph then shows each kind, and each can have its own options and failure route. A single Step type with a kind field hides them.

Core implementation

static_parallel_steps_flow.pyPython
class WorkA(Step[str]):
def execute(self, context: Context, input: str) -> StepDecision:
return graceful_complete(f"A:{input}")


class WorkB(Step[str]):
def execute(self, context: Context, input: str) -> StepDecision:
return graceful_complete(f"B:{input}")


class InitStep(Step[str]):
def execute(self, context: Context, input: str) -> StepDecision:
return go_to_many(
StepMovement.of(WorkA, input),
StepMovement.of(WorkB, input),
)

Example: examples/python/dex_examples/patterns/parallel/static_parallel_steps_flow.py

Next