saga
Skill15 starsChanged 43 days agoMITView on GitHub
Expert Saga pattern implementation covering orchestration, choreography, and compensating transactions. Use when designing distributed transactions, multi-service workflows, or eventual consistency.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- simota/agent-skillstheir own version, first seen Oct 23, 2026
- warpdotdev/common-skillstheir own version, first seen Oct 20, 2026
- thesammykins/skillstheir own version, first seen Aug 14, 2026
- Torus-Intelligence/sagatheir own version, first seen Jun 19, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- warpdotdev/common-skills★ 630same name
- simota/agent-skills★ 96same name
- thesammykins/skills★ 0same name
- Torus-Intelligence/saga★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- xgboostSkill
- api-gatewaySkill
- clean-architectureSkill
- cqrsSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- hexagonalSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- serverlessSkill
- service-meshSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
3
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 126
Prefer Orchestration for Complex Multi-Step Sagas: Use workflow orchestrators (Temporal, AWS Step Functions) for complex multi-branch sagas.
- Distinctive: line 134
Use distributed locks across sagas: Avoid blocking local resources while waiting for distant service responses.
- Distinctive: line 135
Use choreography for sagas with > 4 services: Event-driven choreography becomes impossible to trace and reason about at scale.
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Saga Pattern
The Saga pattern manages data consistency across microservices in distributed transaction scenarios without two-phase commit (2PC). A Saga coordinates a sequence of local transactions, executing compensating transactions backward if any intermediate step fails.
When to Use
- Distributed Transactions Across Microservices: Coordinating multi-step business transactions without two-phase commit (2PC) locks.
- E-Commerce Checkout & Fulfillment: Managing sequences spanning inventory reservation, payment charging, order placement, and delivery dispatch.
- Long-Running Business Processes: Orchestrating processes that span seconds, minutes, or hours with explicit failure compensation.
- Failure Recovery & State Reversal: Rolling back partially completed distributed steps using compensating transactions.
Quick Start
// Minimal Orchestrator-based Saga Definition
interface SagaStep<TContext> {
name: string;
execute: (ctx: TContext) => Promise<void>;
compensate: (ctx: TContext) => Promise<void>;
}
async function runSaga<T>(context: T, steps: SagaStep<T>[]) {
const executedSteps: SagaStep<T>[] = [];
try {
for (const step of steps) {
console.log(`Executing step: ${step.name}`);
await step.execute(context);
executedSteps.push(step);
}
console.log("Saga completed successfully.");
} catch (err) {
console.error(
`Saga failed. Rolling back compensating transactions...`,
err,
);
for (const step of executedSteps.reverse()) {
try {
await step.compensate(context);
} catch (compErr) {
console.error(`Compensation failed for ${step.name}:`, compErr);
}
}
throw err;
}
}Core Concepts
Orchestration vs Choreography Sagas
Sagas coordinate multi-service transactions using either a centralized orchestrator or decentralized events:
[ Orchestrator ] ──1. Reserve Stock──→ [ Inventory Service ]
──2. Charge Card───→ [ Payment Service ] (FAILS!)
──3. Compensate: Release Stock ──→ [ Inventory Service ]Compensating Transactions (Semantic Rollback)
Because local transactions commit at each step, failures must be undone semantically through compensating transactions:
| Forward Transaction | Compensating Transaction |
ReserveStock(orderId, items) | ReleaseStock(orderId, items) |
ChargeCreditCard(amount) | RefundCreditCard(amount) |
CreateShipmentLabel() | CancelShipmentLabel() |
Orchestrator State Machine Definition
Tracks workflow progression and triggers compensation on error:
// sagas/order-saga-orchestrator.ts
export class OrderSagaOrchestrator {
async execute(order: OrderPayload) {
let stockReserved = false;
try {
await inventoryService.reserve(order.id, order.items);
stockReserved = true;
await paymentService.charge(order.id, order.total);
await shippingService.schedule(order.id);
} catch (err) {
console.error("Saga failed! Initiating compensation...", err);
if (stockReserved) {
await inventoryService.compensateRelease(order.id, order.items);
}
throw new Error("Order processing failed; changes compensated.");
}
}
}Common Patterns
Idempotent Step Execution
Problem: Network retries during step execution can result in duplicate orders or double charges.
Solution: Pass an idempotency key with every saga step command:
async function processPayment(orderId: string, idempotencyKey: string) {
const existing = await paymentDb.findByKey(idempotencyKey);
if (existing) {
return existing.result; // Return previous outcome without recharging
}
const result = await paymentGateway.charge(orderId);
await paymentDb.save({ idempotencyKey, orderId, result });
return result;
}Best Practices
Do:
- Prefer Orchestration for Complex Multi-Step Sagas: Use workflow orchestrators (Temporal, AWS Step Functions) for complex multi-branch sagas.
- Make Compensating Transactions Idempotent: Ensure compensation actions can be safely retried multiple times without side effects.
- Record Saga State Persistently: Store the current step and execution state in a durable outbox/database before calling external services.
- Design for Forward Recovery: When possible, retry or alert operators to fix transient issues rather than compensating immediately.
Don't:
- Assume compensating transactions can never fail: Implement alerts and manual intervention queues for failed compensations.
- Use distributed locks across sagas: Avoid blocking local resources while waiting for distant service responses.
- Use choreography for sagas with > 4 services: Event-driven choreography becomes impossible to trace and reason about at scale.
Troubleshooting
| Error | Cause | Solution |
Saga stuck in PENDING | Orchestrator crashed or message dropped in queue. | Use persistent state machines (e.g., Temporal/Step Functions) with automated timeout retries. |
Compensation Failed | Compensating action encountered non-retryable error. | Flag transaction for operator review and write to dead-letter queue (DLQ). |
Duplicate Step Execution | Retry occurred without idempotency check. | Enforce unique idempotency keys per saga step execution. |
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

