Skip to content

Compensating Workflows Pattern #4665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: v1.16
Choose a base branch
from

Conversation

cicoyle
Copy link
Contributor

@cicoyle cicoyle commented May 29, 2025

Adding docs for a new workflow pattern: compensating workflows

I added a java example here. This is just a first pass implementation that could be improved upon, but wanted to document the new pattern

@hhunter-ms can you add a diagram to my PR and tweak it as you see fit?

cicoyle added 2 commits May 29, 2025 14:29
Signed-off-by: Cassandra Coyle <[email protected]>
Signed-off-by: Cassandra Coyle <[email protected]>
@msfussell
Copy link
Member

@marcduiker - Let's think over a diagram we could add into the docs and presentation deck

Copy link
Contributor

@marcduiker marcduiker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a diagram for this, but this will be part of another PR since I want to update all the workflow related diagrams #4679 .

@@ -1386,6 +1386,195 @@ func raiseEvent() {

External events don't have to be directly triggered by humans. They can also be triggered by other systems. For example, a workflow may need to pause and wait for a payment to be received. In this case, a payment system might publish an event to a pub/sub topic on receipt of a payment, and a listener on that topic can raise an event to the workflow using the raise event workflow API.

## Compensation

The compensation pattern provides a mechanism for rolling back or undoing operations that have already been executed when a workflow fails partway through. This pattern is particularly important for long-running workflows that span multiple microservices where traditional database transactions are not feasible.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The compensation pattern provides a mechanism for rolling back or undoing operations that have already been executed when a workflow fails partway through. This pattern is particularly important for long-running workflows that span multiple microservices where traditional database transactions are not feasible.
The compensation pattern (also known as the saga pattern) provides a mechanism for rolling back or undoing operations that have already been executed when a workflow fails partway through. This pattern is particularly important for long-running workflows that span multiple microservices where traditional database transactions are not feasible.

ctx.getLogger().info("Order shipped: {}", shipmentId);
compensations.add("CancelShipment");

// Step 4: Send confirmation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to remove this activity. It's a bit confusing now if the SendConfirmation throws, then the rest is still compensated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants