Saga patterns for distributed transactions with orchestration and choreography approaches. Use when implementing multi-service transactions, handling partial failures, or building systems requiring eventual consistency with compensation.
View on GitHubyonatangross/skillforge-claude-plugin
orchestkit-complete
January 23, 2026
Select agents to install to:
npx add-skill https://github.com/yonatangross/skillforge-claude-plugin/blob/main/./skills/saga-patterns/SKILL.md -a claude-code --skill saga-patternsInstallation paths:
.claude/skills/saga-patterns/# Saga Patterns for Distributed Transactions
Maintain consistency across microservices without distributed locks.
## Overview
- Multi-service business transactions (order -> payment -> inventory -> shipping)
- Operations that must eventually succeed or roll back completely
- Long-running business processes (minutes to days)
- Microservices avoiding 2PC (two-phase commit)
## When NOT to Use
- Single database operations (use transactions)
- Real-time consistency requirements (use synchronous calls)
- When eventual consistency is unacceptable
## Orchestration vs Choreography
| Aspect | Orchestration | Choreography |
|--------|---------------|--------------|
| Control | Central orchestrator | Distributed events |
| Coupling | Services depend on orchestrator | Loosely coupled |
| Visibility | Single point of observation | Requires distributed tracing |
| Best for | Complex, ordered workflows | Simple, parallel flows |
## Orchestration Pattern
```python
from enum import Enum
from dataclasses import dataclass, field
from typing import Callable, Any
from datetime import datetime, timezone
class SagaStatus(Enum):
PENDING = "pending"
RUNNING = "running"
COMPLETED = "completed"
COMPENSATING = "compensating"
COMPENSATED = "compensated"
FAILED = "failed"
@dataclass
class SagaStep:
name: str
action: Callable
compensation: Callable
status: SagaStatus = SagaStatus.PENDING
result: Any = None
@dataclass
class SagaContext:
saga_id: str
data: dict = field(default_factory=dict)
steps: list[SagaStep] = field(default_factory=list)
status: SagaStatus = SagaStatus.PENDING
current_step: int = 0
class SagaOrchestrator:
def __init__(self, saga_repository, event_publisher):
self.repo = saga_repository
self.publisher = event_publisher
async def execute(self, saga: SagaContext) -> SagaContext:
saga.status = SagaStatus.RUNNING
await self.repo.save(saga)
for i, step in enum