Skip to content

feat: Add compensation workflow pattern to Spring Boot examples#1696

Open
siri-varma wants to merge 6 commits intodapr:masterfrom
siri-varma:master
Open

feat: Add compensation workflow pattern to Spring Boot examples#1696
siri-varma wants to merge 6 commits intodapr:masterfrom
siri-varma:master

Conversation

@siri-varma
Copy link
Contributor

Port the BookTrip compensation (Saga) workflow from the plain Java examples into the Spring Boot workflow patterns module, adding @Component-annotated activities and a /wfp/compensation REST endpoint.

Description

Please explain the changes you've made

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #1395

#1395

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

@siri-varma siri-varma marked this pull request as ready for review March 13, 2026 21:56
@siri-varma siri-varma requested review from a team as code owners March 13, 2026 21:56
Port the BookTrip compensation (Saga) workflow from the plain Java
examples into the Spring Boot workflow patterns module, adding
@Component-annotated activities and a /wfp/compensation REST endpoint.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Siri Varma Vegiraju <svegiraju@Siris-MacBook-Pro.local>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a Spring Boot “compensation / Saga” workflow pattern example (BookTrip) to the workflows/patterns module, along with a REST endpoint to trigger it.

Changes:

  • Introduces BookTripWorkflow implementing a simple saga with compensating activities.
  • Adds booking and cancellation workflow activities as Spring components.
  • Exposes a new POST /wfp/compensation endpoint to run the workflow and return its output.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/CancelHotelActivity.java Adds hotel-cancellation activity for compensation flow
spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/CancelFlightActivity.java Adds flight-cancellation activity for compensation flow
spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/CancelCarActivity.java Adds car-cancellation activity for compensation flow
spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookTripWorkflow.java Implements saga-style orchestration with compensation retries
spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookHotelActivity.java Adds hotel booking activity used by the workflow
spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookFlightActivity.java Adds flight booking activity used by the workflow
spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookCarActivity.java Adds car booking activity that intentionally fails to trigger compensation
spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/WorkflowPatternsRestController.java Adds POST /wfp/compensation endpoint to run the new workflow

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Siri Varma Vegiraju <siri.varma@outlook.com>
@salaboy
Copy link
Collaborator

salaboy commented Mar 16, 2026

@siri-varma I am a bit against this way of doing compensations, that's why I've created this example: https://github.com/diagrid-labs/workflow-patterns-spring-boot?tab=readme-ov-file#compensate-on-error-example I think that having an arraylist inside the workflow itself is a hack and should be avoided.

Check this specifically: https://github.com/diagrid-labs/workflow-patterns-spring-boot/blob/main/workflows/src/main/java/io/dapr/springboot/workflows/compensateonerror/CompensateWhenErrorWorkflow.java#L40

Check the example and let me know if you have any questions, I would rather have an example following that approach in the SDK than a port from other languages.

Copy link
Collaborator

@salaboy salaboy left a comment

Choose a reason for hiding this comment

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

Check my comment in the PR

@codecov
Copy link

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.53%. Comparing base (5ee71c0) to head (c73444b).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1696      +/-   ##
============================================
- Coverage     79.54%   79.53%   -0.02%     
- Complexity     2196     2197       +1     
============================================
  Files           238      238              
  Lines          6591     6591              
  Branches        732      732              
============================================
- Hits           5243     5242       -1     
- Misses          990      992       +2     
+ Partials        358      357       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SpringBoot Example: Compensation Workflow

3 participants