agentleFS
d-padmanabhand-padmanabhan/agent-engineering-handbook/skills/distributed-transactions/SKILL.md

distributed-transactions

Skill17 starsChanged 56 days agoMITView on GitHub

Designs and reviews cross-service consistency using Transactional Outbox/Inbox, Saga orchestration, Saga choreography, compensating actions, idempotency, and eventual consistency. Use when the user mentions outbox, inbox, saga, orchestration, choreography, compensation, distributed transaction, dual write, CDC relay, duplicate delivery, or cross-service workflow consistency.

The file

Show its rules and text

We split this skill into the rules it gives an agent

19 rules. About 0 are common, 17 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈17

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when one business operation spans services, databases, brokers, or external systems and cannot rely on one local ACID …

    line 8
  2. Distinctive:

    Prefer one local ACID transaction when the data can remain inside one ownership boundary.

    line 12
  3. Distinctive:

    Every design must preserve declared business invariants across success, retries, concurrency, partial failure, compensation, and recovery.

    line 13
  4. Distinctive:

    Never implement a database write followed by direct message publication as an unprotected dual write.

    line 16
  5. Distinctive:

    One service and one database: use a local transaction.

    line 26
  6. Distinctive:

    Publish an event after a local state change: use Transactional Outbox.

    line 27
  7. Distinctive:

    Protect a consumer from duplicate business effects: use Inbox/deduplication, a domain idempotency key, or both.

    line 28
  8. Distinctive:

    Before proposing implementation, document:

    line 36
  9. Distinctive:

    Do not start with a framework or broker feature.

    line 49
  10. Distinctive:

    Write the domain change and Outbox row in the same local transaction.

    line 53
  11. Very specific:

    Use the Outbox and Inbox reference (${HANDBOOK_ROOT}/skills/distributed-transactions/references/outbox-inbox.md) for schema, relay, CDC, …

    line 57
  12. Distinctive:

    no central component needs to decide the next step.

    line 73
  13. Very specific:

    Use the Saga reference (${HANDBOOK_ROOT}/skills/distributed-transactions/references/saga-orchestration-choreography.md) for state, …

    line 78
  14. Distinctive:

    Use stable operation and message identifiers generated before retries.

    line 82
  15. Distinctive:

    Keep handlers deterministic around recorded input.

    line 86
  16. Distinctive:

    Use dead-letter handling only with ownership, alerts, replay safety, and a runbook.

    line 87
  17. Distinctive:

    Never log secrets or unrestricted payloads.

    line 101
  18. Distinctive:

    Test failure boundaries, not only the happy path:

    line 105
  19. Distinctive:

    Use deterministic fault injection and verify durable state after each interruption.

    line 117

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Distributed Transactions

Use this skill when one business operation spans services, databases, brokers, or external systems and cannot rely on one local ACID transaction.

Non-Negotiables

  • Prefer one local ACID transaction when the data can remain inside one ownership boundary.
  • Every design must preserve declared business invariants across success, retries, concurrency, partial failure, compensation, and recovery. Never imply that eventual consistency or a Saga provides global ACID semantics.
  • Never implement a database write followed by direct message publication as an unprotected dual write.
  • Assume messages can be delayed, duplicated, reordered, and redelivered.
  • Make externally visible commands and consumers idempotent at the business-effect boundary.
  • Acknowledging or committing a message is not proof that the business effect occurred exactly once.
  • Compensation is a new business action, not a database rollback. It can fail and may require human resolution.
  • Persist workflow state, deadlines, attempts, and decisions durably. Do not keep authoritative Saga state only in process memory.
  • Bound retries and timeouts; quarantine poison messages and expose reconciliation paths.

Choose the Simplest Correct Pattern

  1. One service and one database: use a local transaction.
  2. Publish an event after a local state change: use Transactional Outbox.
  3. Protect a consumer from duplicate business effects: use Inbox/deduplication, a domain idempotency key, or both.
  4. A short cross-service flow with clear central ownership and complex compensation: prefer Saga orchestration.
  5. A loosely coupled event reaction with few participants and no central workflow state: choreography may fit.
  6. Many ordered steps, long waits, approvals, deadlines, or operational intervention: use a durable workflow engine or explicit orchestrator.
  7. Strong global atomicity is genuinely mandatory: reconsider service/data boundaries before reaching for distributed locking or two-phase commit.

Design Workflow

Before proposing implementation, document:

  • business invariant and consistency boundary;
  • participating services and data owners;
  • commands, events, correlation ID, causation ID, aggregate ID, and idempotency keys;
  • state machine, terminal states, deadlines, retry policy, and concurrency policy;
  • compensation for each completed step and what cannot be compensated;
  • message ordering requirements and partition/routing key;
  • duplicate, stale, late, and out-of-order handling;
  • operator visibility, reconciliation query, replay policy, and manual-resolution path;
  • schema/version evolution and deployment compatibility;
  • retention and cleanup for Outbox, Inbox, workflow, and audit records.

Do not start with a framework or broker feature. Start with invariants and failure modes.

Transactional Outbox and Inbox

Write the domain change and Outbox row in the same local transaction. A separate relay publishes pending rows and marks publication progress without assuming publish-and-mark is atomic. Give each event a stable identifier and enough routing/version metadata for deterministic handling.

Consumers must make duplicate delivery harmless. Record processed message identity in the same local transaction as the business effect where possible. A transport-level dedupe window alone is insufficient for long-lived business guarantees.

Use the Outbox and Inbox reference (${HANDBOOK_ROOT}/skills/distributed-transactions/references/outbox-inbox.md) for schema, relay, CDC, polling, retention, and recovery details.

Saga Orchestration and Choreography

Prefer orchestration when

  • the workflow has many steps, branches, waits, or deadlines;
  • compensation order matters;
  • one team owns the end-to-end process;
  • operators need one authoritative workflow state;
  • participants should not know the full process.

Prefer choreography when

  • reactions are independently valuable and loosely coupled;
  • the participant graph is small and understandable;
  • no central component needs to decide the next step;
  • event contracts and ownership remain clear without circular dependencies.

Choreography is not “no orchestration”; the emergent event graph becomes the workflow and must still be observable, versioned, bounded, and testable.

Use the Saga reference (${HANDBOOK_ROOT}/skills/distributed-transactions/references/saga-orchestration-choreography.md) for state, compensation, isolation anomalies, timeouts, and recovery.

Reliability Contract

  • Use stable operation and message identifiers generated before retries.
  • Distinguish retrying transport from retrying the business command.
  • Reject or ignore stale state transitions with an explicit version or expected-state check.
  • Serialize operations per aggregate when concurrent transitions would violate invariants.
  • Keep handlers deterministic around recorded input; isolate nondeterministic calls behind persisted results.
  • Use dead-letter handling only with ownership, alerts, replay safety, and a runbook.
  • Reconciliation compares authoritative business state to Outbox, Inbox, broker, and workflow state; it does not blindly replay everything.

Observability

Emit structured events and metrics for:

  • workflow state transitions and age;
  • relay backlog age and publish attempts;
  • duplicate and stale-message counts;
  • retry, timeout, compensation, and manual-resolution counts;
  • dead-letter depth and oldest-message age;
  • correlation and causation across every command and event.

Never log secrets or unrestricted payloads. Prefer identifiers, state, schema version, and redacted failure context.

Testing

Test failure boundaries, not only the happy path:

  • crash after domain commit but before publish;
  • publish succeeds but publication marking fails;
  • duplicate, delayed, stale, and out-of-order delivery;
  • consumer crash before and after local commit;
  • concurrent commands for the same aggregate;
  • timeout followed by a late success;
  • compensation failure and repeated compensation;
  • schema version skew during rolling deployment;
  • replay from dead-letter storage and reconciliation repair.

Use deterministic fault injection and verify durable state after each interruption.

Review Output

For a design or code review, report:

  1. Invariant and boundary
  2. Critical correctness risks
  3. Chosen pattern and why
  4. Message/workflow state contract
  5. Idempotency, ordering, timeout, and compensation behavior
  6. Recovery and reconciliation
  7. Tests and operational signals

Reject vague claims such as “Kafka guarantees exactly once” or “the Saga rolls everything back.” State the actual end-to-end guarantee and its limits.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.