SAGA compensation with child workflow

I making a PoC with temporal which include a main workflow which spawn a child workflow. I used the SAGA pattern to compensate the activities in the main workflow, but I’m wondering how I could compensate the activities in the child workflow.
Changing the ParentClosePolicy does not seem to have an impact on the child, as the child finish before the end of the parent workflow.
And as you cannot have several methods in a workflow, I can’t call a compensate method in the child workflow.

So I guess I have to write another child workflow for compensation which will try to erase any steps that may have be done by the first child workflow. And I would need to call this compensation workflow in the error handling of the main workflow.

But is there a better way to do it ?

The following works:

  1. A parent starts a child
  2. The child executes the happy path
  3. At the end of the happy path, the child blocks waiting for a signal from the parent
  4. At the end of the parent execution, it notifies all children with either a “commit” or an “abort signal”.
  5. Each child either completes or executes the rollback logic based on the signal received from the parent.
1 Like

If I understand correctly (in java), I have to launch the child workflow in async. And in the WorkflowMethod, I use Workflow.await(…) that will be triggered by a SignalMethod.

However if I need the return value of my child WorkflowMethod, I have to wait for the end of my main workflow to either commit or rollback the child workflow and then get the value of the Promise returned by the async child workflow method, once the child workflow get deblocked and end.

Am I wrong or is there another method to get a return value before the end of the child workflow ?

The child workflow can return the result in a signal. Then the sequence becomes:

  1. A parent starts a child
  2. The child executes the happy path
  3. At the end of the happy path, the child sends a signal with its result to the parent and blocks waiting for a signal from the parent
  4. At the end of the parent execution, it notifies all children with either a “commit” or an “abort signal”.
  5. Each child either completes or executes the rollback logic based on the signal received from the parent.

Now, I have a clear view of the different solutions to my problem.
Thanks for your reply and your time.