
Saga Orchestration
FreeManage distributed transactions without two-phase commit.
Free · Opens the source repo
What Saga Orchestration does
Saga Orchestration provides a structured approach to managing distributed transactions and long-running business processes in microservices architectures. When traditional two-phase commit (2PC) is unavailable, this skill helps implement saga patterns that ensure data consistency across multiple services. It is particularly useful in scenarios where compensating actions are necessary for workflows that span various domains, such as inventory, payment, and shipping services. By defining service boundaries, transaction requirements, and failure modes, users can create robust workflows that handle partial failures gracefully.
The skill produces a comprehensive saga definition that includes ordered steps, action commands, and compensation commands tailored to the specific needs of the application. It allows developers to implement either orchestrator or choreography patterns, depending on the architecture of their system. Additionally, it provides the necessary compensation logic for each service involved, ensuring that all actions are idempotent and can be retried without adverse effects. With configurable timeouts and monitoring setups, users can effectively manage the lifecycle of their sagas and detect any issues that may arise during execution.
This skill is ideal for developers and designers working on complex systems where transactions span multiple services and require careful coordination. It is especially beneficial for those building order fulfillment systems, travel booking applications, or any other processes that necessitate atomic operations across distributed services. By leveraging saga orchestration, teams can replace fragile 2PC mechanisms with more resilient asynchronous compensation strategies, ultimately leading to more reliable applications.
When to use it
Use this skill when coordinating multi-service transactions, especially in scenarios where compensating transactions are necessary due to partial failures.
When not to use it
This skill may not be suitable for simple applications with few services or where strong consistency can be guaranteed without complex orchestration.
What you can build with it
Order Fulfillment System
Implement a saga to coordinate inventory, payment, and shipping services, ensuring that all steps are compensated if any fail.
Travel Booking Application
Use saga orchestration to manage hotel, flight, and car rental reservations, allowing for rollback of all bookings if one fails.
Event-Driven Microservices
Design a saga that utilizes asynchronous messaging to handle distributed transactions across multiple microservices without direct service coupling.
How to install Saga Orchestration
View source1. Install with the skills CLI
npx skills add wshobson/agents/saga-orchestration --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by wshobsonSaga Orchestration
Patterns for managing distributed transactions and long-running business processes without two-phase commit.
Inputs and Outputs
What you provide:
- Service boundaries and ownership (which service owns which step)
- Transaction requirements (which steps must be atomic, which can be eventual)
- Failure modes for each step (transient vs. permanent, retry policy)
- SLA requirements per step (informs timeout configuration)
- Existing event/messaging infrastructure (Kafka, RabbitMQ, SQS, etc.)
What this skill produces:
- Saga definition with ordered steps, action commands, and compensation commands
- Orchestrator or choreography implementation for your chosen pattern
- Compensation logic for each participant service (idempotent, always-succeeds)
- Step timeout configuration with per-step deadlines
- Monitoring setup: state machine metrics, stuck saga detection, DLQ recovery
When to Use This Skill
- Coordinating multi-service transactions without distributed locks
- Implementing compensating transactions for partial failures
- Managing long-running business workflows (minutes to hours)
- Handling failures in distributed systems where atomicity is required
- Building order fulfillment, approval, or booking processes
- Replacing fragile two-phase commit with async compensation
Detailed section: Core Concepts
Moved to references/details.md.
Detailed section: Templates
Moved to references/details.md.
Best Practices
Do's
- Make every step idempotent — Commands may be replayed on broker reconnect
- Design compensations carefully — They are the most critical code path
- Use correlation IDs — The
saga_idmust flow through every event and log - Implement per-step timeouts — Never wait indefinitely for a participant reply
- Log state transitions —
saga_id,step_name,old_state → new_stateon every change - Test compensation paths explicitly — Inject failures at each step index in integration tests
Don'ts
- Don't assume instant completion — Sagas are async and may take minutes
- Don't skip compensation testing — The rollback path is the hardest to get right
- Don't couple services directly — Use async messaging, never synchronous calls inside a saga step
- Don't ignore partial failures — A step that partially executed still needs compensation
- Don't use a global timeout — Each step has different latency characteristics
Troubleshooting
Saga stuck in COMPENSATING state
A saga enters compensation but never reaches FAILED. This means a compensation handler is throwing an unhandled exception and never publishing SagaCompensationCompleted. Add dead-letter queue (DLQ) handling to compensation consumers and ensure every compensation action publishes a result event even when the underlying operation was already rolled back.
async def handle_release_reservation(self, command: Dict):
try:
await self.release_reservation(command["original_result"]["reservation_id"])
except ReservationNotFoundError:
pass # Already released — treat as success
# Always publish completion, regardless of outcome
await self.event_publisher.publish("SagaCompensationCompleted", {
"saga_id": command["saga_id"],
"step_name": "reserve_inventory"
})
Duplicate saga executions on restart
If your orchestrator service restarts mid-saga, it may replay events and re-execute already-completed steps. Guard every step action with an idempotency key — see Template 3 above.
Choreography saga losing events
In a choreography-based saga, a downstream service may miss an event if it was offline when published. Use a durable message broker (Kafka with replication, RabbitMQ with persistence) and store the current saga state in a dedicated saga_log table so you can replay from the last known good step.
Timeout firing before a slow-but-valid step completes
A step like create_shipment might take up to 15 minutes during peak load but your global timeout is 5 minutes, causing spurious compensation. Make step timeouts configurable per step type — see references/advanced-patterns.md for the TimeoutSagaOrchestrator implementation and the STEP_TIMEOUTS dict pattern.
Compensation order not matching execution order
When two steps both complete before a failure is detected, compensation must run in strict reverse order or you leave data in an inconsistent state. Verify that _compensate() iterates from current_step - 1 down to 0, and add an integration test that deliberately fails at each step index to confirm correct rollback order.
Advanced Patterns
The references/ directory contains production-grade implementations not needed for most sagas:
references/advanced-patterns.md— FullSagaOrchestratorabstract base class,TimeoutSagaOrchestratorwith per-step deadlines, detailed bank transfer compensating transaction chain, Prometheus instrumentation, stuck saga PromQL alerts, and DLQ recovery worker.
Related Skills
cqrs-implementation— Pair sagas with CQRS for read-model updates after each step completesevent-store-design— Store saga events in an event store for full audit trail and replay capabilityworkflow-orchestration-patterns— Higher-level workflow engines (Temporal, Conductor) that build on saga concepts
Frequently asked questions about Saga Orchestration
Similar skills
Python PyPI Package Builder
Streamline the process of creating and publishing Python packages.
Minecraft Plugin Development
Streamline your Minecraft server plugin creation.
MCP Server Builder
Easily build .NET MCP servers with the latest standards.
CommunityToolkit.Mvvm Messenger
Decoupled communication for ViewModels in .NET applications.
MVVM Toolkit DI
Streamline ViewModel integration with Dependency Injection in .NET.
MCP Apps Builder
Essential guidelines for MCP server development.
