Skip to content

Compensation API Reference

Details on how the compensation mechanism (Saga Pattern) works in Orchestrix.

The compensate Function

Defined in StepOptions.

ts
compensate?: (ctx: FlowContext<TInput>) => Promise<void> | void;

Execution Rules

  1. Reverse Order: Compensations run in reverse order of step completion.
  2. Trigger: Triggered when a subsequent step fails permanently (exhausts retries) or times out.
  3. Context Access: The compensation function has full access to the FlowContext, allowing it to read data stored during the original step execution.
  4. Error Handling: If a compensation function itself fails, Orchestrix will catch the error, trigger the onCompensationError hook, and continue with the next compensation in the queue.
  • onCompensate: Triggered before a compensation starts.
  • onCompensateComplete: Triggered after a compensation finishes successfully.

Released under the MIT License.