saga-orchestration
What it does
This tool helps manage complex processes involving multiple systems. It ensures that if one part fails, the entire process can be undone in an organized way, like undoing a multi-step purchase (payment, inventory, shipping).
When to use it
- βWhen coordinating actions across multiple systems without locking everything.
- βTo undo operations that have partially failed.
- βWhen managing long-running processes that might take hours.
Skill link
https://github.com/wshobson/agents/blob/main/plugins/backend-development/skills/saga-orchestration/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow can I ensure a purchase is correctly canceled if shipping fails after payment has been processed?β
5 new skills a week. 1 minute to read.
How it works
It defines the steps of a process, what to do at each step, and how to undo each step if something goes wrong. This is done asynchronously, without locking up systems.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Saga 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
β¦
FAQ
What is a 'distributed transaction'?
It's an operation that involves multiple systems or databases and needs to be treated as a single unit: either everything succeeds, or nothing does.
What does 'compensation' mean?
It's the action of undoing what has already been done in a previous step of a process, should a later step fail. For example, refunding a payment if the product cannot be shipped.
Why not use 'two-phase commit' (2PC)?
2PC can lock systems and doesn't work well in modern distributed environments. Sagas use a more flexible, asynchronous model.
Details
Original description by the author
Implement saga patterns for distributed transactions and cross-aggregate workflows. Use this skill when implementing distributed transactions across microservices where 2PC is unavailable, designing compensating actions for failed order workflows that span inventory, payment, and shipping services, building event-driven saga coordinators for travel booking systems that must roll back hotel, flight
repo: wshobson/agents
Popularity
- GitHub stars
- 41k
- Ranking position
- #6641
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
screen-reader-testing
41kHas your agent test websites using screen readers to ensure they are accessible.
wcag-audit-patterns
41kHelps your agent audit websites for accessibility and fix issues according to WCAG guidelines.
multi-reviewer-patterns
41kEnables your agent to coordinate parallel code reviews, deduplicating findings and consolidating reports.
parallel-debugging
41kAllows the agent to debug complex issues with parallel investigations and root cause analysis.
Similar skills
api-connector-builder
280kHas your agent build new API connections following the existing pattern. Use when you need to add one more integration without creating a new way of doing things.
api-design
280kHelps your agent design REST APIs following best practices. It's useful for defining how APIs communicate, how errors are shown, and how to organize data.
backend-patterns
280kHelps your agent with server-side architecture patterns and database optimization. It's useful for building or reviewing code that runs on the server.