You describe a process as states and the transitions between them. The engine carries each instance along that map, runs the actions you placed at every stop, and remembers where it is. Four ideas cover most of it: the definition, the state, the transition and the action.
A process is one JSON document. You can draw it on the canvas or type it; both edit the same thing. It has five parts worth knowing.
01The definitionOne JSON document per process. key names it, and the server gives every published copy a version. initialState is where each instance starts. defaultErrorState is where a failure goes when nothing closer catches it.
{ "key": "loan-approval", "initialState": "intake", "defaultErrorState": "system-error", "variables": { "schema": { "amount": { "type": "number", "required": true }, "decision": { "type": "string", "writeAccess": ["human"] } } }, "states": { "manual-review": { "kind": "human", "onEntry": [ { "id": "open-case", "type": "db", "assignTo": "caseId" } ], "human": { "candidateRoles": ["reviewer"], "outputVar": "decision" }, "transitions": [ { "id": "t-approve", "to": "approved", "priority": 1, "guard": { "$expr": "vars.decision === 'approve'" }, "actions": [ { "id": "stamp-case", … } ] }, { "id": "t-reject", "to": "rejected", "default": true } ], "onExit": [ { "id": "reviewed", "type": "publish" } ] }, "approved": { "kind": "terminal", "outcome": "approved" } }}Condensed for the page: action config blocks and the other states are left out.
One JSON document per process. key names it, and the server gives every published copy a version. initialState is where each instance starts. defaultErrorState is where a failure goes when nothing closer catches it.
The data an instance carries. Declare a type, required values and defaults, and say with writeAccess who may set each one: the start input, an action, a person or an event.
The stations. Each state has a kind that decides what happens there, and a block for that kind. Here it is a human task for the reviewer role.
The work. A state runs its onEntry list when the instance arrives and its onExit list when it leaves. Every action has a type: http, db, email, publish and seven more.
The lines to the next state. A guard is an expression over the variables, priority orders the tries and default is the fallback. A transition can carry actions of its own.
Every state follows the same order: its onEntry actions, the wait that belongs to its kind, the choice of a transition, that transition's actions, then onExit. Follow one instance through a review step.
01EnterThe instance arrives at manual-review. The engine writes a state-enter entry to its history.
The instance arrives at manual-review. The engine writes a state-enter entry to its history.
The state's onEntry actions run in the order they are written, one at a time. Each can write its result to a variable.
This is a human state, so the instance parks. A task is created for the reviewer role and the state is saved in PostgreSQL. Nothing holds a thread while it waits.
A reviewer completes the task. The answer is written to vars.decision and the instance wakes up.
Transitions are tried in priority order. The first whose guard is true wins, and a default catches the rest. Here vars.decision === 'approve' holds.
The chosen transition can carry actions of its own. They run now, before the state is left.
Then the state's onExit actions run. They run on every normal exit, whichever transition was taken.
The instance enters approved and that state's onEntry begins. Every step leaves a history entry and a snapshot of the variables.
An automatic state skips the wait: it runs onEntry and picks a transition at once. A fork has no onExit, because it leaves along every branch.
A state's kind decides what the instance does when it gets there: pass through, wait for something, split, meet or stop.
automaticRuns its actions and moves on at once. It never waits.
waitParks until an event, a signal or a broker message arrives.
humanParks with a task for a person. The outcome they choose picks the way out.
timerParks until its timer fires, then leaves.
callStarts a child process and parks until the child ends.
forkStarts one branch per transition, side by side.
joinWhere a fork's branches meet and their variables merge.
terminalEnds the instance with an outcome.
Actions do the work of a process: call a service, query a database, send a message, run a script, ask an agent. All thirteen types share one envelope, so every action can be conditional, time-limited, retried and undone in the same way.
Evaluated first. Only a strict true runs the action. Anything else skips it, and a skip is never a failure.
The settings of the action's type. Every $expr inside is resolved from the variables, the context and the secrets.
The action runs under its time limit. With an idempotencyKey, a side effect that already completed is replayed from the ledger, not sent twice.
Decides what a failure does: fail, continue, retry with a back-off, or catch to an error state named in catchTo.
Where the result goes: one variable path with assignTo, or merge to fold a returned object into the variables.
The action's undo step. Once the action has run, the step is on the instance's log. If a later failure is routed to an error state, the logged steps run newest first.
Illustrative: an http action named charge. The same envelope wraps all thirteen action types.
A failure that survives its retries does not just stop the process. It is routed, and what was already done can be undone.
The target is the action's catchTo, or else the definition's defaultErrorState.
Every action that ran with a compensate step left it on the instance's log. Before the error state is entered, the engine runs that log backwards.
Its onEntry runs as on any entry. The failing state is left without running its onExit.
It keeps its history, its variables and its undo log. An operator can retry it, move it to another state or cancel it.
Undo steps are business logic you write, not a rollback across systems. Design external effects to be safe to repeat.
Read about compensation and errorsBigger behaviour comes from combining states, transitions and actions. These are the combinations people reach for first.
Run a list of actions for every item of an array, one after the other or up to 16 at once. Run branches of actions side by side.
forEach · parallelA fork state starts one branch per transition. The join continues when all have arrived, the first, or n of them.
fork · joinCall another definition and wait for its result, or start it and go on without waiting.
call · callProcessResume a waiting instance from an event, a signal or a RabbitMQ or Kafka message. Start an instance when a message arrives.
wait · triggers · publishGive a task a due date with an escalation route. Fire reminders while the instance keeps waiting where it is.
dueInMs · onDue · boundaryTimersTag neighbouring database actions to run in one database transaction. The group can be retried as a whole on a conflict.
transactionGroupSix patterns show these parts working together: approvals, durable waits, parallel work, child processes, events and compensation.
Explore the patterns