Zum Inhalt springen
Skillpedia
APIs & Server (Backend)41k · #6641

saga-orchestration

Was er macht

Dieses Tool hilft dir, komplexe Prozesse zu steuern, die mehrere Systeme betreffen. Es sorgt dafür, dass sich der gesamte Ablauf auf geordnete Weise rückgängig machen lässt, wenn ein Teil fehlschlägt. Ein Beispiel ist ein Kauf mit mehreren Schritten: Zahlung, Lager und Versand.

Wann du ihn nutzt

  • ✓Wenn du Aktionen über mehrere Systeme hinweg koordinieren willst, ohne alles zu blockieren.
  • ✓Um Vorgänge rückgängig zu machen, die teilweise fehlgeschlagen sind.
  • ✓Wenn du langlaufende Prozesse verwaltest, die Stunden dauern können.

Link zum Skill

https://github.com/wshobson/agents/blob/main/plugins/backend-development/skills/saga-orchestration/SKILL.md

Kopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum Einfügen

Nutze diesen Skill, um mir zu helfen: https://github.com/wshobson/agents/blob/main/plugins/backend-development/skills/saga-orchestration/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen für meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Wie stelle ich sicher, dass ein Kauf korrekt storniert wird, wenn der Versand fehlschlägt, nachdem die Zahlung bereits verarbeitet wurde?”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Es legt die Schritte eines Prozesses fest, was in jedem Schritt passieren soll und wie sich jeder Schritt rückgängig machen lässt, falls etwas schiefgeht. Das läuft asynchron ab, ohne Systeme zu blockieren.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von 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_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

…

Häufige Fragen

Was ist eine „verteilte Transaktion“?

Das ist ein Vorgang, der mehrere Systeme oder Datenbanken betrifft und als einzelne Einheit behandelt werden muss. Entweder klappt alles, oder es klappt nichts.

Was bedeutet „Kompensation“?

Das ist die Aktion, die einen bereits ausgeführten Schritt eines Prozesses rückgängig macht, wenn ein späterer Schritt fehlschlägt. Ein Beispiel ist die Rückerstattung der Zahlung, wenn das Produkt nicht versendet werden kann.

Warum nicht „Two-Phase Commit“ (2PC) verwenden?

2PC kann Systeme blockieren und funktioniert in modernen verteilten Umgebungen nicht gut. Sagas nutzen ein flexibleres, asynchrones Modell.

Details

Originalbeschreibung des Autors

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

Beliebtheit

GitHub-Sterne
41k
Platz im Ranking
#6641
Lizenz
MIT
Aktualisiert
15.10.2026

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills