Saga Orchestration
Seth HobsonCommunityCreated by Seth Hobson
- Skill
- Tool integration
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured approach to managing distributed transactions and long-running business processes without relying on two-phase commit. It covers both orchestration and choreography patterns, offering templates for defining steps, compensation logic, and state management. By focusing on idempotency, correlation IDs, and asynchronous messaging, it enables developers to build resilient systems that handle partial failures and maintain data consistency across service boundaries.
What it does
- Defines ordered saga steps with associated action and compensation commands
- Provides base classes for orchestrator-based saga management
- Implements idempotent compensation logic for participant services
- Configures per-step timeouts and deadline management
- Establishes monitoring patterns for state machine tracking and stuck saga detection
- Supports choreography-based saga design for event-driven architectures
When to use it
- Coordinating multi-service transactions without distributed locks
- Implementing compensating transactions for partial failures in microservices
- Managing long-running business workflows that span minutes or hours
- Replacing fragile two-phase commit protocols with asynchronous compensation
- Building reliable order fulfillment, booking, or approval processes
Advantages
- Enables atomicity in distributed systems where 2PC is unavailable
- Improves system resilience through explicit failure handling and rollbacks
- Decouples services by utilizing asynchronous event-driven communication
- Provides clear patterns for handling partial failures and state recovery
- Ensures consistent data states through idempotent compensation actions
Usage examples
- “How do I define a saga for an order fulfillment process?”
- The skill provides a template for an OrderFulfillmentSaga class that defines steps for inventory, payment, shipping, and notification, including specific compensation actions for each.
- “What should I do if a saga gets stuck in the COMPENSATING state?”
- The skill advises adding dead-letter queue handling to compensation consumers and ensuring every compensation action publishes a completion event, even if the operation was already rolled back.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/wshobson/saga-orchestration/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip saga-orchestration.zip -d .agents/skills
Documentation by Seth Hobson
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 logImplement per-step timeouts — Never wait indefinitely for a participant reply
Log state transitions —
saga_id,step_name,old_state → new_stateon every changeTest 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
Files
- ATTRIBUTION.mdAdded by AutoGineer992 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md5.9 KiB
- references/advanced-patterns.md14.8 KiB
- references/details.md9.8 KiB
LICENSE
MIT License Copyright (c) 2024 Seth Hobson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Seth Hobson
- Publisher
- Seth Hobson (Community)
- Source
- wshobson/agents · plugins/backend-development/skills/saga-orchestration · commit 4bde316
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Seth Hobson.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download saga-orchestration.zip