Superseded by 0102: the workflow engine runs steps
in-process with a Postgres journal; authoring is the declarative
@Step graph of 0094.Context
Multi-step business operations (create order, charge, reserve stock) must be able to undo earlier steps when a later one fails. Services own their data (0014) and call each other through events or clients, so database transactions cannot span them. A step-and-compensation model, as in Medusa, fits and is readable.Decision
- A package
@stackra/workflowprovidescreateStep(name, invoke, compensate?)andcreateWorkflow(name, composer). - A step has an optional compensation function. On failure, completed steps are compensated in reverse order.
- Steps and workflows are resolved through the container (0042); workflows live in a module’s
application/(0040). - Step inputs and outputs are typed; a workflow’s input and output are its public contract.
- Steps are idempotent so a retry or a re-compensation is safe.
- Persistence of workflow state, retries and long-running execution are not decided here (TODO).
Consequences
- Cross-service operations get one shape and one place to look for rollback logic.
- Without persisted state, a crash mid-workflow loses compensation; point 6 must be settled before money flows through it.
- Package category: TODO (see 0028).