distributed-systems
Skill6 starsChanged 8 months agoMITView on GitHub
Apply distributed systems patterns including idempotency, saga pattern, outbox pattern, eventual consistency, and CQRS to build reliable, consistent distributed services.
5 other projects use a version of this.
Adopted by
Most recently taken up by
- bjornjee/skillstheir own version, first seen Sep 8, 2026
- ctxswitch/skillstheir own version, first seen Sep 7, 2026
- 2867203296/hermes-agenttheir own version, first seen Aug 19, 2026
- aresbit/claude-skillstheir own version, first seen Jul 12, 2026
- ffsshhttiikk/opencode-agents-skillstheir own version, first seen Feb 28, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- bjornjee/skills★ 2same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- ctxswitch/skills★ 1same name
- 2867203296/hermes-agent★ 0same name
- aresbit/claude-skills★ 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 repository64 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- api-backward-compatibilitySkill
- api-design-standardsSkill
- api-versioningSkill
- database-designSkill
- observability-by-defaultSkill
- performance-budgetsSkill
- resilience-patternsSkill
- twelve-factor-appSkill
- codex-cross-reviewSkill
- dispatching-parallel-agentsSkill
- receiving-code-reviewSkill
- requesting-code-reviewSkill
- subagent-driven-developmentSkill
- architecture-awarenessSkill
- intent-to-specSkill
- project-diagnosisSkill
- using-shipworthySkill
- systematic-debuggingSkill
- documentation-as-codeSkill
- accessibilitySkill
- frontend-standardsSkill
- retrospectiveSkill
- writing-skillsSkill
- ci-cd-awarenessSkill
- context-managerSkill
- environment-setupSkill
- feature-flag-disciplineSkill
- finishing-a-development-branchSkill
- guardrail-audit-logSkill
- incident-responseSkill
- mcp-integrationSkill
- migration-strategiesSkill
- production-readinessSkill
- scope-creep-detectionSkill
- session-memorySkill
- slo-sli-definitionSkill
- tech-debt-trackingSkill
- using-git-worktreesSkill
- zero-downtime-migrationsSkill
- brainstormingSkill
- decision-frameworksSkill
- design-documentsSkill
- executing-plansSkill
- writing-plansSkill
- code-complexitySkill
- confidence-based-strictnessSkill
- error-handling-patternsSkill
- feedback-driven-adaptationSkill
- quality-gatesSkill
- response-schema-validationSkill
- test-driven-developmentSkill
- verification-before-completionSkill
- adaptive-securitySkill
- bias-detectionSkill
- compliance-awarenessSkill
- container-securitySkill
- dependency-managementSkill
- pii-detectionSkill
- secrets-managementSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 7 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
7
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 19
When to apply: Every mutation endpoint in your API.
- Distinctive: line 109
Use a database unique constraint on the key to prevent races.
- Distinctive: line 111
If the original request failed, delete the key so the client can retry.
- Distinctive: line 206
Write the business data AND the outbox message in the same database transaction.
- Distinctive: line 208
After successful publish, mark the outbox row as sent.
- Distinctive: line 254
Use Change Data Capture (CDC) with Debezium for higher throughput instead of polling.
- Distinctive: line 295
When to apply: Use CQRS when read and write patterns differ significantly.
“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
Distributed Systems Patterns
Core Principle
In a distributed system, you cannot have both strong consistency and high availability during a network partition (CAP theorem). Design for eventual consistency where possible, and use patterns that make the system correct even when components fail independently.
1. Idempotency
What it does: Ensures that performing the same operation multiple times produces the same result as performing it once. This is essential because in distributed systems, messages can be delivered more than once.
When to apply: Every mutation endpoint in your API. Every message consumer. Every payment or state-changing operation.
Idempotency Key Pattern for APIs
The client generates a unique key and sends it with the request. The server stores the result keyed by this value and returns the stored result on duplicate requests.
// Client sends: POST /v1/charges
// Header: Idempotency-Key: idem_a1b2c3d4
async function handleChargeRequest(req: Request): Promise<Response> {
const idempotencyKey = req.headers['idempotency-key'];
if (!idempotencyKey) {
return errorResponse(400, 'Idempotency-Key header is required');
}
// Check if we already processed this key
const existing = await idempotencyStore.get(idempotencyKey);
if (existing) {
if (existing.status === 'processing') {
return errorResponse(409, 'Request is already being processed');
}
return existing.response; // Return the stored response
}
// Lock the key to prevent concurrent processing
await idempotencyStore.set(idempotencyKey, { status: 'processing' });
try {
const result = await processCharge(req.body);
const response = successResponse(201, result);
await idempotencyStore.set(idempotencyKey, {
status: 'completed',
response,
expiresAt: Date.now() + 24 * 60 * 60 * 1000, // 24h TTL
});
return response;
} catch (error) {
await idempotencyStore.delete(idempotencyKey); // Allow retry on failure
throw error;
}
}Python Example -- Database-backed Idempotency
from functools import wraps
from datetime import datetime, timedelta
def idempotent(ttl_hours=24):
def decorator(fn):
@wraps(fn)
def wrapper(idempotency_key: str, *args, **kwargs):
# Check existing result
existing = db.idempotency_keys.find_one({"key": idempotency_key})
if existing and existing["status"] == "completed":
return existing["result"]
if existing and existing["status"] == "processing":
raise ConflictError("Request already in progress")
# Lock
db.idempotency_keys.insert_one({
"key": idempotency_key,
"status": "processing",
"created_at": datetime.utcnow(),
})
try:
result = fn(*args, **kwargs)
db.idempotency_keys.update_one(
{"key": idempotency_key},
{"$set": {
"status": "completed",
"result": result,
"expires_at": datetime.utcnow() + timedelta(hours=ttl_hours),
}},
)
return result
except Exception:
db.idempotency_keys.delete_one({"key": idempotency_key})
raise
return wrapper
return decoratorRules for Idempotency Keys
- Keys must be client-generated UUIDs (UUIDv4 or UUIDv7).
- Store results for at least 24 hours before expiring.
- Use a database unique constraint on the key to prevent races.
- Return the same HTTP status code and body for duplicate requests.
- If the original request failed, delete the key so the client can retry.
2. Saga Pattern
What it does: Manages distributed transactions across multiple services by breaking them into a sequence of local transactions, each with a compensating action (rollback).
When to apply: Any business process that spans multiple services and must be logically atomic (e.g., order placement that involves inventory, payment, and shipping).
Orchestration (Centralized Coordinator)
A single saga orchestrator service directs each step and handles compensation on failure.
Orchestrator -> InventoryService.reserve()
-> PaymentService.charge()
-> ShippingService.schedule()
If PaymentService.charge() fails:
Orchestrator -> InventoryService.releaseReservation() // compensateclass OrderSaga {
async execute(order: Order): Promise<SagaResult> {
const steps: SagaStep[] = [
{
action: () => inventoryService.reserve(order.items),
compensate: () => inventoryService.release(order.items),
},
{
action: () => paymentService.charge(order.customerId, order.total),
compensate: () => paymentService.refund(order.customerId, order.total),
},
{
action: () => shippingService.schedule(order.id, order.address),
compensate: () => shippingService.cancel(order.id),
},
];
const completedSteps: SagaStep[] = [];
for (const step of steps) {
try {
await step.action();
completedSteps.push(step);
} catch (error) {
// Compensate in reverse order
for (const completed of completedSteps.reverse()) {
await completed.compensate();
}
return { status: 'failed', error };
}
}
return { status: 'completed' };
}
}Choreography (Event-Driven, Decentralized)
Each service listens for events and triggers the next step. No central coordinator.
OrderService emits OrderCreated
-> InventoryService listens, reserves stock, emits StockReserved
-> PaymentService listens, charges card, emits PaymentCompleted
-> ShippingService listens, schedules delivery, emits OrderShipped
If PaymentService fails, it emits PaymentFailed
-> InventoryService listens, releases stockWhen to Use Which
| Factor | Orchestration | Choreography |
| Number of steps | 4+ steps | 2-3 steps |
| Visibility | Easy to trace and debug | Hard to follow event chains |
| Coupling | Services depend on orchestrator | Services are fully decoupled |
| Complexity | Logic centralized | Logic distributed across services |
| Best for | Complex business workflows | Simple event chains |
3. Outbox Pattern
What it does: Guarantees that a database write and a message/event publication happen atomically, preventing lost or duplicate messages.
When to apply: Any time you need to update a database AND publish an event. This is the correct solution to the dual-write problem.
How It Works
- Write the business data AND the outbox message in the same database transaction.
- A separate process (poller or CDC) reads the outbox table and publishes messages to the message broker.
- After successful publish, mark the outbox row as sent.
-- Step 1: Write both in one transaction
BEGIN;
INSERT INTO orders (id, customer_id, total, status)
VALUES ('ord_123', 'cust_456', 99.99, 'created');
INSERT INTO outbox (id, aggregate_type, aggregate_id, event_type, payload, created_at)
VALUES (
'evt_789',
'Order',
'ord_123',
'OrderCreated',
'{"orderId": "ord_123", "customerId": "cust_456", "total": 99.99}',
NOW()
);
COMMIT;# Step 2: Outbox poller (runs on a schedule, e.g., every 1 second)
def poll_and_publish():
unsent = db.execute(
"SELECT * FROM outbox WHERE sent_at IS NULL ORDER BY created_at LIMIT 100"
)
for event in unsent:
try:
message_broker.publish(
topic=f"{event.aggregate_type}.{event.event_type}",
key=event.aggregate_id,
value=event.payload,
)
db.execute(
"UPDATE outbox SET sent_at = NOW() WHERE id = %s", (event.id,)
)
except Exception as e:
log.warning(f"Failed to publish {event.id}, will retry: {e}")
break # Preserve ordering -- stop on first failureKey rules:
- The outbox table and the business table must be in the same database.
- Consumers must be idempotent because the poller may publish a message more than once (at-least-once delivery).
- Use Change Data Capture (CDC) with Debezium for higher throughput instead of polling.
4. Eventual Consistency
What it does: Accepts that data across services will be temporarily inconsistent but will converge to a consistent state given enough time.
When to apply: Most inter-service data flows. Strong consistency across services is extremely expensive and fragile. Reserve strong consistency for within a single service/database.
Documenting Consistency Guarantees
For every service-to-service data flow, document:
- What is the consistency window? (e.g., "Order status propagates to the analytics service within 5 seconds under normal load.")
- What happens during inconsistency? (e.g., "Dashboard may show stale order counts for up to 5 seconds.")
- How do you detect inconsistency? (e.g., "Reconciliation job runs hourly and alerts if counts diverge by more than 1%.")
- How do you resolve inconsistency? (e.g., "Re-publish events from the outbox for the affected time window.")
Reconciliation Pattern
def reconcile_orders():
"""Run hourly to detect and fix inconsistencies between OrderService and AnalyticsService."""
order_counts = order_service.get_counts_by_status(since=hours_ago(2))
analytics_counts = analytics_service.get_counts_by_status(since=hours_ago(2))
for status, expected_count in order_counts.items():
actual_count = analytics_counts.get(status, 0)
if abs(expected_count - actual_count) > expected_count * 0.01:
alert(f"Inconsistency detected: {status} orders expected={expected_count} actual={actual_count}")
# Trigger re-sync for affected records
order_service.republish_events(status=status, since=hours_ago(2))5. CQRS (Command Query Responsibility Segregation)
What it does: Uses separate models (and often separate databases) for reading and writing data.
When to apply: Use CQRS when read and write patterns differ significantly. Do NOT use it by default -- it adds significant complexity.
When CQRS is Worth the Complexity
| Signal | Use CQRS | Do Not Use CQRS |
| Read/write ratio | >10:1 reads to writes | Roughly equal reads and writes |
| Read model shape | Very different from write model | Same shape as write model |
| Scale requirements | Reads must scale independently | Uniform scaling is sufficient |
| Query complexity | Complex aggregations across entities | Simple lookups by ID |
| Team size | Team can maintain two models | Small team, keep it simple |
Practical Example
// Write side -- optimized for consistency and validation
class OrderCommandHandler {
async createOrder(cmd: CreateOrderCommand): Promise<void> {
const order = new Order(cmd);
order.validate();
await this.orderRepository.save(order); // Write to normalized DB
await this.eventBus.publish(new OrderCreated(order)); // Publish event
}
}
// Read side -- optimized for query performance
class OrderQueryHandler {
// Reads from a denormalized read-optimized store (e.g., Elasticsearch, Redis)
async getOrderDashboard(customerId: string): Promise<OrderDashboard> {
return this.readStore.query({
customerId,
includes: ['orderSummary', 'recentActivity', 'spendingTrends'],
});
}
}
// Projection -- keeps the read model in sync
class OrderProjection {
async onOrderCreated(event: OrderCreated): Promise<void> {
await this.readStore.upsert({
id: event.orderId,
customerId: event.customerId,
status: 'created',
total: event.total,
createdAt: event.timestamp,
});
}
}Checklist Before Shipping a Distributed System
- Every API mutation endpoint accepts an idempotency key.
- Multi-service workflows use the saga pattern with explicit compensation.
- Database writes + event publishing use the outbox pattern (no dual writes).
- Consistency windows are documented for every inter-service data flow.
- Reconciliation jobs exist to detect and correct drift.
- CQRS is only used where read/write asymmetry justifies the complexity.
- Every message consumer is idempotent.
- Saga state is persisted so it survives process restarts.
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.

