Langsung ke konten
Skillpedia
API & server (backend)41k Β· #6641

saga-orchestration

Fungsinya

Alat ini membantu mengelola proses rumit yang melibatkan banyak sistem. Alat ini memastikan bahwa jika satu bagian gagal, seluruh proses bisa dibatalkan dengan tertib, seperti membatalkan pembelian multi-langkah (pembayaran, stok, pengiriman).

Kapan dipakai

  • βœ“Saat mengoordinasikan aksi di beberapa sistem tanpa mengunci semuanya.
  • βœ“Untuk membatalkan operasi yang gagal sebagian.
  • βœ“Saat mengelola proses yang berjalan lama, bisa sampai berjam-jam.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/wshobson/agents/blob/main/plugins/backend-development/skills/saga-orchestration/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œBagaimana cara memastikan pembelian dibatalkan dengan benar jika pengiriman gagal setelah pembayaran diproses?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Alat ini mendefinisikan langkah-langkah proses, apa yang harus dilakukan di tiap langkah, dan bagaimana membatalkan tiap langkah jika terjadi kesalahan. Semua ini dilakukan secara asinkron, tanpa mengunci sistem.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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

…

Pertanyaan umum

Apa itu 'distributed transaction'?

Itu adalah operasi yang melibatkan banyak sistem atau database dan harus diperlakukan sebagai satu kesatuan: semuanya berhasil, atau tidak ada yang berhasil.

Apa arti 'compensation'?

Itu adalah tindakan untuk membatalkan apa yang sudah dilakukan di langkah sebelumnya, jika langkah berikutnya gagal. Contohnya, mengembalikan dana pembayaran jika produk tidak bisa dikirim.

Mengapa tidak menggunakan 'two-phase commit' (2PC)?

2PC bisa mengunci sistem dan kurang cocok untuk lingkungan terdistribusi modern. Saga menggunakan model yang lebih fleksibel dan asinkron.

Detail

Deskripsi asli dari pembuat

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

Popularitas

Bintang GitHub
41k
Peringkat
#6641
Lisensi
MIT
Diperbarui
15/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa