/giuseppe-trisciuoglio:spring-boot-saga-patternfrom giuseppe-trisciuoglio
Provides distributed transaction patterns using the Saga Pattern in Spring Boot microservices. Use when building microservices requiring transaction management across multiple services, handling compensating transactions, ensuring eventual consistency, or implementing choreography or orchestration-based sagas with Spring Boot, Kafka, or Axon Framework.
Ships in giuseppe-trisciuoglio. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Implement this skill when:
Trigger phrases: distributed transactions, saga pattern, compensating transactions, microservices transaction, eventual consistency, rollback across services, orchestration pattern, choreography pattern
The Saga Pattern is an architectural pattern for managing distributed transactions in microservices. Instead of using a single ACID transaction across multiple databases, a saga breaks the transaction into a sequence of local transactions. Each local transaction updates its database and publishes an event or message to trigger the next step. If a step fails, the saga executes compensating transactions to undo the changes made by previous steps.
When implementing a saga, make these decisions:
Follow these steps to implement saga pattern for distributed transactions:
Identify all services involved in the business process. Map out the sequence of local transactions and their corresponding compensating transactions.
Select choreography (event-driven, decentralized) or orchestration (centralized coordinator) based on team expertise and system complexity.
Create events for each transaction step (OrderCreated, PaymentProcessed, InventoryReserved). Include correlationId for tracing.
Ensure each service can complete its local transaction atomically within its own database boundary.
For each forward operation, implement a compensating operation that reverses the effect (cancel order, refund payment, release inventory).
Configure Kafka or RabbitMQ with appropriate topics/queues. Implement idempotent message consumers.
Create a saga orchestrator service that tracks saga state, sends commands to participants, and handles compensations on failure.
Set up event listeners in each service that react to events from other services and trigger next steps.
Implement timeout mechanisms for each saga step. Configure dead-letter queues for messages that exceed processing time limits.
Track saga execution status, duration, and failure rates. Set up alerts for stuck or failed sagas.
Each microservice publishes events and listens to events from other services. No central coordinator.
Best for: Greenfield microservice applications with few participants
Advantages:
Disadvantages:
A central orchestrator manages the entire transaction flow and tells services what to do.
Best for: Brownfield applications, complex workflows, or when centralized control is needed
Advantages:
Disadvantages:
Identify the sequence of operations and corresponding compensating transactions:
Order → Payment → Inventory → Shipment → Notification
↓ ↓ ↓ ↓ ↓
Cancel Refund Release Cancel Cancel
Each service handles its local ACID transaction and publishes events or responds to commands.
Every forward transaction must have a corresponding compensating transaction. Ensure idempotency and retryability.
Implement retry logic, timeouts, and dead-letter queues for failed messages.
Spring Boot 3.x with dependencies:
Messaging: Spring Cloud Stream, Apache Kafka, RabbitMQ, Spring AMQP
Saga Frameworks: Axon Framework (4.9.0), Eventuate Tram Sagas, Camunda, Apache Camel
Persistence: Spring Data JPA, Event Sourcing (optional), Transactional Outbox Pattern
Monitoring: Spring Boot Actuator, Micrometer, Distributed Tracing (Sleuth + Zipkin)
❌ Tight Coupling: Services directly calling each other instead of using events ❌ Missing Compensations: Not implementing compensating transactions for every step ❌ Non-Idempotent Operations: Compensations that cannot be safely retried ❌ Synchronous Sagas: Waiting synchronously for each step (defeats the purpose) ❌ Lost Messages: Not handling message delivery failures ❌ No Monitoring: Running sagas without visibility into their status ❌ Shared Database: Using same database across multiple services ❌ Ignoring Network Failures: Not handling partial failures gracefully
Do not implement this pattern when:
@Transactional
public Order createOrder(OrderRequest request) {
Order order = orderRepository.save(request);
paymentService.charge(request.getPayment());
inventoryService.reserve(request.getItems());
shippingService.schedule(order);
return order;
}
@Service
public class OrderSagaOrchestrator {
public OrderSummary createOrder(OrderRequest request) {
// Step 1: Create order
Order order = orderService.createOrder(request);
try {
// Step 2: Process payment
Payment payment = paymentService.processPayment(
new PaymentRequest(order.getId(), request.getAmount()));
// Step 3: Reserve inventory
InventoryReservation reservation = inventoryService.reserve(
new InventoryRequest(order.getItems()));
// Step 4: Schedule shipping
Shipment shipment = shippingService.schedule(
new ShipmentRequest(order.getId()));
return OrderSummary.completed(order, payment, reservation, shipment);
} catch (PaymentFailedException e) {
// Compensate: cancel order
orderService.cancelOrder(order.getId());
throw e;
} catch (InsufficientInventoryException e) {
// Compensate: refund payment, cancel order
paymentService.refund(payment.getId());
orderService.cancelOrder(order.getId());
throw e;
}
}
}
// Event published when order is created
@EventHandler
public void on(OrderCreatedEvent event) {
// Trigger payment processing
paymentService.processPayment(event.getOrderId());
}
@Service
public class OrderEventHandler {
@KafkaListener(topics = "order.created")
public void handleOrderCreated(OrderCreatedEvent event) {
try {
paymentService.processPayment(event.toPaymentRequest());
} catch (PaymentException e) {
kafkaTemplate.send("order.payment.failed", new PaymentFailedEvent(event.getOrderId()));
}
}
}
@Service
public class PaymentEventHandler {
@KafkaListener(topics = "payment.processed")
public void handlePaymentProcessed(PaymentProcessedEvent event) {
inventoryService.reserve(event.toInventoryRequest());
}
@KafkaListener(topics = "payment.failed")
public void handlePaymentFailed(PaymentFailedEvent event) {
orderService.cancelOrder(event.getOrderId());
}
}
@Service
public class InventoryEventHandler {
@KafkaListener(topics = "inventory.reserved")
public void handleInventoryReserved(InventoryReservedEvent event) {
shippingService.scheduleShipment(event.toShipmentRequest());
}
@KafkaListener(topics = "inventory.insufficient")
public void handleInsufficientInventory(InsufficientInventoryEvent event) {
// Compensate: refund payment
paymentService.refund(event.getPaymentId());
// Compensate: cancel order
orderService.cancelOrder(event.getOrderId());
}
}
For detailed information, consult the following resources:
See also examples.md for complete implementation examples:
references/01-saga-pattern-definition.md (opens in a new tab)references/02-choreography-implementation.md (opens in a new tab)references/03-orchestration-implementation.md (opens in a new tab)references/04-event-driven-architecture.md (opens in a new tab)references/05-compensating-transactions.md (opens in a new tab)references/06-state-management.md (opens in a new tab)references/07-error-handling-retry.md (opens in a new tab)references/08-testing-strategies.md (opens in a new tab)references/09-pitfalls-solutions.md (opens in a new tab)references/examples.md (opens in a new tab)references/reference.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub ulpi-io/plugin-marketplace --plugin giuseppe-trisciuoglio95 skills in this plugin
/aws-cloudformation-auto-scalingaws-rds-spring-boot-integrationProvides patterns to configure AWS RDS (Aurora, MySQL, PostgreSQL) with Spring Boot applications. Use when setting up datasources, connection pooling, security, and production-ready database configuration./aws-cloudformation-bedrockaws-sdk-java-v2-bedrockProvides Amazon Bedrock patterns using AWS SDK for Java 2.x. Use when working with foundation models (listing, invoking), text generation, image generation, embeddings, streaming responses, or integrating generative AI with Spring Boot applications./aws-cloudformation-cloudfrontOther plugins' skills for the same job