← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Saga Pattern

Messaging Advanced
debt(d9/e9/b9/t7)
d9 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9). detection_hints.automated is no; saga bugs (missing compensations, lost correlation IDs) manifest as data inconsistency in production, no tool catches them.

e9 Effort Remediation debt — work required to fix once spotted

Closest to 'architectural rework' (e9). Adding compensating transactions, correlation IDs, and orchestrator state persistence per quick_fix is not a patch — it's redesigning the distributed transaction flow across multiple services.

b9 Burden Structural debt — long-term weight of choosing wrong

Closest to 'defines the system's shape' (b9). Per applies_to (web/cli/queue) and tags (distributed-transactions, microservices), saga is the backbone of cross-service consistency; every new cross-service operation must conform to it.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). Per misconception, devs assume ACID semantics but get ACI with no isolation — directly contradicts how local DB transactions behave, leading to wrong assumptions about rollback and visibility.

About DEBT scoring →

TL;DR

The Saga pattern manages distributed transactions across services using a sequence of local transactions — each step publishes an event, and compensating transactions undo completed steps on failure.

Explanation

Distributed transactions across microservices can't use 2PC (too slow, too coupled). Saga: a sequence of local transactions (T1, T2, ..., Tn) where each Ti publishes an event triggering Ti+1. On failure at Ti: run compensating transactions (C(i-1), ..., C1) to undo. Two styles: choreography (each service publishes events and other services react — no central coordinator) and orchestration (a Saga orchestrator sends commands to services and handles failures centrally). Choreography: decoupled but hard to trace. Orchestration: easier to monitor and debug. PHP: Symfony Messenger workflows, custom saga state machine.

Common Misconception

Sagas provide ACID guarantees — they provide ACI (no isolation). Other transactions can see intermediate saga state. Use compensating logic, not database rollback.

Why It Matters

Saga is the standard solution for distributed transactions in microservices — without it, services either couple via distributed transactions (2PC) or leave data inconsistent.

Common Mistakes

  • No compensating transactions defined — partial failures leave data inconsistent.
  • Choreography without correlation ID — impossible to trace saga execution.
  • Not handling compensating transaction failures — need retry + alerting.

Code Examples

✗ Vulnerable
// 2PC across services — tight coupling, deadlock risk:
$coordinator->prepare('order-service', $orderTx);
$coordinator->prepare('payment-service', $paymentTx);
$coordinator->commit(); // Both or neither
✓ Fixed
// Saga orchestration:
// 1. OrderService.createOrder() → publishes OrderCreated
// 2. PaymentService.processPayment() → publishes PaymentProcessed
// 3. InventoryService.reserveItems() → publishes ItemsReserved
// On PaymentFailed: publish OrderCancelled → inventory released

$sagaState = ['order_id' => $orderId, 'step' => 'payment', 'status' => 'pending'];
// Orchestrator retries failed steps, triggers compensations on unrecoverable failure

Added 23 Mar 2026
Views 66
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 2 pings T 1 ping F 0 pings S 5 pings S 2 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 10 Perplexity 9 Scrapy 8 Google 5 SEMrush 5 Ahrefs 3 Bing 3 ChatGPT 3 Unknown AI 2 Claude 2 Meta AI 1 PetalBot 1
crawler 48 crawler_json 4
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: High
⚡ Quick Fix
Define compensating transactions for every step. Assign correlation ID to track saga state. Use orchestration for complex sagas (easier to debug). Persist saga state between steps.
📦 Applies To
web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
saga|compensat
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File Tests: Update


✓ schema.org compliant