
Spring Boot Saga Pattern
Implement choreography-based distributed sagas in Spring Boot so order, payment, inventory, and shipment services stay consistent without a central orchestrator.
Overview
Spring Boot Saga Pattern is an agent skill for the Build phase that guides choreography-based saga design and Spring Boot event publishing for distributed transactions.
Install
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill spring-boot-saga-patternWhat is this skill?
- Choreography-based saga: no central coordinator; each service reacts to domain events
- Documents success path (OrderCreated → PaymentProcessed → InventoryReserved → ShipmentPrepared)
- Documents failure path with PaymentFailed, OrderCancelled, and cross-service cleanup
- Includes OrderEventPublisher pattern using Spring Cloud Stream StreamBridge
- Compensation flows tied to event listeners on each participating service
- Four-service success path: order, payment, inventory, shipment
- Failure path centered on PaymentFailed and OrderCancelled events
Adoption & trust: 1.2k installs on skills.sh; 271 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You are splitting a monolith into services but cannot keep order, payment, and inventory in sync when any step fails mid-flow.
Who is it for?
Indie builders adding event-driven sagas to a Spring Boot API or ecommerce backend with multiple bounded contexts.
Skip if: Teams that need a single orchestration service with explicit state machines only, or non-JVM stacks with no Spring messaging.
When should I use this skill?
Designing or coding distributed sagas, event compensation, or Spring Boot messaging for multi-step business flows.
What do I get? / Deliverables
You get a clear choreography event model, publisher/listener patterns, and compensation triggers you can implement in Spring Boot services.
- Choreography event diagram and step/compensation narrative for your domain
- Event publisher and listener patterns aligned to your service names
Recommended Skills
Journey fit
Saga patterns are applied while designing and coding microservice backends and event-driven workflows. The skill centers on Java Spring Boot services, StreamBridge event publishing, and compensation paths—core backend architecture work.
How it compares
Architecture guidance for distributed sagas—not a drop-in Terraform module or a generic CRUD generator.
Common Questions / FAQ
Who is spring-boot-saga-pattern for?
Solo and indie backend developers using Spring Boot who are implementing microservices and need choreography-style sagas with domain events and compensations.
When should I use spring-boot-saga-pattern?
During Build backend work when you are defining OrderCreated/PaymentProcessed-style flows, wiring StreamBridge publishers, or planning rollback when payment or inventory steps fail.
Is spring-boot-saga-pattern safe to install?
It is documentation and code-pattern guidance; review the Security Audits panel on this page before trusting the skill package in your agent environment.
SKILL.md
READMESKILL.md - Spring Boot Saga Pattern
# Choreography-Based Saga Implementation ## Architecture Overview In choreography-based sagas, each service produces and listens to events. Services know what to do when they receive an event. **No central coordinator** manages the flow. ``` Service A → Event → Service B → Event → Service C ↓ ↓ ↓ Event Event Event ↓ ↓ ↓ Compensation Compensation Compensation ``` ## Event Flow ### Success Path 1. **Order Service** creates order → publishes `OrderCreated` event 2. **Payment Service** listens → processes payment → publishes `PaymentProcessed` event 3. **Inventory Service** listens → reserves inventory → publishes `InventoryReserved` event 4. **Shipment Service** listens → prepares shipment → publishes `ShipmentPrepared` event ### Failure Path (When Payment Fails) 1. **Payment Service** publishes `PaymentFailed` event 2. **Order Service** listens → cancels order → publishes `OrderCancelled` event 3. All other services respond to cancellation with cleanup ## Event Publisher ```java @Component public class OrderEventPublisher { private final StreamBridge streamBridge; public OrderEventPublisher(StreamBridge streamBridge) { this.streamBridge = streamBridge; } public void publishOrderCreatedEvent(String orderId, BigDecimal amount, String itemId) { OrderCreatedEvent event = new OrderCreatedEvent(orderId, amount, itemId); streamBridge.send("orderCreated-out-0", MessageBuilder .withPayload(event) .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON) .build()); } } ``` ## Event Listener ```java @Component public class PaymentEventListener { @Bean public Consumer<OrderCreatedEvent> handleOrderCreatedEvent() { return event -> processPayment(event.getOrderId()); } private void processPayment(String orderId) { // Payment processing logic } } ``` ## Event Classes ```java public record OrderCreatedEvent( String orderId, BigDecimal amount, String itemId ) {} public record PaymentProcessedEvent( String paymentId, String orderId, String itemId ) {} public record PaymentFailedEvent( String paymentId, String orderId, String itemId, String reason ) {} ``` ## Spring Cloud Stream Configuration ```yaml spring: cloud: stream: bindings: orderCreated-out-0: destination: order-events paymentProcessed-out-0: destination: payment-events paymentFailed-out-0: destination: payment-events kafka: binder: brokers: localhost:9092 ``` ## Maven Dependencies ```xml <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream-binder-kafka</artifactId> </dependency> ``` ## Gradle Dependencies ```groovy implementation 'org.springframework.cloud:spring-cloud-stream' implementation 'org.springframework.cloud:spring-cloud-stream-binder-kafka' ``` ## Advantages and Disadvantages ### Advantages - **Simple** for small number of services - **Loose coupling** between services - **No single point of failure** - Each service is independently deployable ### Disadvantages - **Difficult to track workflow state** - distributed across services - **Hard to troubleshoot** - following event flow is complex - **Complexity grows** with number of services - **Distributed source of truth** - saga state not centralized ## When to Use Choreography Use choreography-based sagas when: - Microservices are few in number (< 5 services per saga) - Loose coupling is critical - Team is experienced with event-driven architecture - System can handle eventual consistency - Workflow doesn't need centralized monitoring