🎯

saga-orchestration

🎯Skill

A guide for keeping multi-step tasks consistent when they span several separate services, like order, payment and shipping. If one step fails, it shows how to cleanly undo the steps already done.

wshobson/agents8,230 Installs27,673Added Jan 31, 2026

Installation

$npx skills add wshobson/agents --skill saga-orchestration

Run it in a terminal; it asks which AI coding tools to install it for (Claude Code, Codex, Cursor and more).

Uses skills.sh Β· Node.js 22.20+

After installing

Ask for related work and the agent uses it on its own, or call it yourself.

Run it (Claude Code)/saga-orchestration
Install by hand

Copy the whole skill folder from GitHub to the place below. Copying only SKILL.md can leave out files the skill uses.

Open the skill folder β†’
  • This project .claude/skills/saga-orchestration/
  • All projects ~/.claude/skills/saga-orchestration/

These paths are for Claude Code. For other tools, the command above puts it in the right place.

What this skill does

Overview

A saga is a way to run a business process as a chain of steps across different services. Each step has a matching undo action, called a compensation, in case a later step fails. This skill helps you design, build and debug these chains.

Key Features

  • Define ordered steps, each with its own action and undo action.
  • Choose between one central coordinator or services reacting to each other's messages.
  • Set a separate time limit for each step instead of one global limit.
  • Track progress and spot sagas that get stuck during undo.
  • Fix common problems, such as repeated steps after a restart or lost messages.

Who is this for?

This is for backend developers building order, booking or approval flows across several services. It is most useful when one shared database transaction is not possible.

Summarized by AI from this skill's SKILL.md. Suggest a better one

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, and car rental reservations atomically, or debugging stuck saga states in production where compensation steps never complete.

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_id must 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_state on 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 β€” Full SagaOrchestrator abstract base class, TimeoutSagaOrchestrator with 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 completes
  • event-store-design β€” Store saga events in an event store for full audit trail and replay capability
  • workflow-orchestration-patterns β€” Higher-level workflow engines (Temporal, Conductor) that build on saga concepts

More from this repository10

🎯
tailwind-design-system🎯Skill

Helps you build a consistent look for your app with Tailwind CSS v4. It sets up shared colors, sizes, dark mode and reusable components so every screen matches.

🎯
typescript-advanced-types🎯Skill

A guide to TypeScript's advanced type features, which describe the shape of your data so mistakes are caught before the code runs. It covers reusable types, types that change based on rules, and built-in helper types, with short examples.

🎯
nodejs-backend-patterns🎯Skill

Guidance for building reliable server-side apps with Node.js, using Express or Fastify. It covers login, error handling, databases, API design and a list of proven best practices.

πŸͺ
wshobson-agentsπŸͺMarketplace

Intelligent automation and multi-agent orchestration for Claude Code

πŸ”Œ
framework-migrationπŸ”ŒPlugin

Claude Code plugin for AI-powered framework migration workflows, coordinating specialized agents to plan and execute transitions between technology stacks as part of the wshobson/agents marketplace.

πŸ”Œ
payment-processingπŸ”ŒPlugin

A Claude Code plugin for payment system integration covering Stripe, PayPal, and billing platforms with checkout flows, subscription management, and webhook handling in the wshobson/agents ecosystem.

πŸ”Œ
developer-essentialsπŸ”ŒPlugin

A Claude Code plugin bundling core development tools and agents for everyday tasks like debugging and code generation, part of the wshobson/agents marketplace with 73 focused plugins.

πŸ”Œ
observability-monitoringπŸ”ŒPlugin

Claude Code plugin for observability and monitoring including logging, metrics, distributed tracing, and alerting, part of the wshobson/agents marketplace with 73 focused plugins.

πŸ”Œ
deployment-strategiesπŸ”ŒPlugin

A Claude Code plugin providing specialized AI agents for deployment strategy planning and execution, covering blue-green deployments, canary releases, rolling updates, and zero-downtime patterns.

πŸ”Œ
jvm-languagesπŸ”ŒPlugin

Claude Code plugin for JVM language development including Java, Kotlin, and Scala with specialized agents for idiomatic patterns, build tools, and runtime optimization in the wshobson/agents marketplace.