Distributed Systems Patterns
Acknowledgement: Shared by Peter Bamuhigire, techguypeter.com, +256 784 464178.
Use When
- Use when designing or reviewing multi-service, message-driven, or eventually consistent systems. Covers service boundaries, consistency tradeoffs, event workflows, outbox and inbox patterns, sagas, ordering, and idempotency.
Do Not Use When
- The change is a single-process transaction with no remote dependency, asynchronous delivery, or independently failing component.
- The task is mainly service decomposition or API shape; use
system-architecture-design or api-design-first and return here for cross-boundary failure semantics.
Required Inputs
| Input |
Required |
Why it matters |
| Workflow steps and system boundaries |
yes |
Identifies where atomicity ends and partial failure begins |
| Delivery, ordering, and consistency requirements |
yes |
Determines idempotency, sequencing, and reconciliation choices |
| Failure and recovery expectations |
yes |
Sets timeout, retry, compensation, and operator intervention rules |
| Throughput and latency constraints |
conditional |
Tests whether the coordination pattern is viable |
Workflow
Draw state transitions and ownership boundaries, enumerate failure windows, choose consistency and coordination patterns, define idempotency and recovery, then verify duplicate, reordered, delayed, and partially applied events.
Quality Standards
Every remote interaction has a timeout and failure policy. Every retried side effect has an idempotency rule. Consistency claims state their scope, and recovery does not assume exactly-once delivery.
Outputs
| Output |
Consumer |
Acceptance condition |
| Distributed workflow model |
Architecture and implementation teams |
Shows state ownership, message boundaries, consistency guarantees, and failure windows |
| Failure-handling contract |
Service owners |
Defines timeout, retry, deduplication, compensation, replay, and reconciliation behavior |
| Verification scenarios |
Test and operations teams |
Cover duplicates, reordering, concurrency, dependency outage, and partial completion |
Evidence Produced
| Category |
Artifact |
Format |
Example |
| Operability |
Service consistency and idempotency note |
Markdown doc covering chosen consistency model, idempotency keys, and saga sequences |
docs/dist/consistency-note-checkout.md |
| Operability |
Failure-mode catalogue |
Markdown doc listing partition, retry, and replay failure modes with mitigations |
docs/dist/failure-modes-checkout.md |
References
- Use the
references/ directory for deep detail after reading the core workflow below.
- Load
references/event-driven-architecture.md for event choreography, event contracts, brokers, and asynchronous workflow design.
- Load
references/realtime-systems.md for WebSocket, SSE, pub/sub, and realtime delivery concerns.
Use this skill when a design crosses process, service, queue, or region boundaries. The goal is to keep distributed complexity deliberate and bounded rather than accidental.
Load Order
- Load
world-class-engineering.
- Load
system-architecture-design first for the overall shape.
- Load this skill only when the system genuinely needs multiple services, asynchronous workflows, or weakly consistent boundaries.
Decision Workflow
1. Justify Distribution
State why distribution is necessary:
- team ownership and release independence
- scaling asymmetry
- fault isolation
- compliance or tenancy isolation
- long-running or bursty workflows
If none of these are strong, prefer a modular monolith.
2. Define Boundaries and Contracts
For each service or asynchronous component, define:
- owned data
- API or event contracts
- consistency expectation
- failure effect on upstream and downstream flows
- observability and ownership requirements
3. Choose Interaction Patterns
Use:
- synchronous calls when the caller needs immediate confirmation
- messaging when work is slow, bursty, or naturally eventual
- outbox and inbox patterns when reliability across boundaries matters
- sagas or compensations when one business workflow spans multiple durable states
4. Design Consistency and Recovery
Make explicit:
- source of truth
- ordering requirements
- deduplication strategy
- reconciliation path
- timeout and retry policy
- compensation or manual repair path
5. Prove the Design
Before calling it production-ready, provide:
- consistency model
- failure-mode examples
- idempotency and replay notes
- contract evolution rules
- operational signals for stuck or divergent workflows
Non-Negotiable Standards
Service Boundaries
- Each service owns its data and rules.
- Do not share databases across services as a convenience.
- Keep contracts narrow and versionable.
- Avoid chatty request chains on critical paths.
Messaging
- Assume at-least-once delivery unless proven otherwise.
- Design consumers to be idempotent and replay-safe.
- Define ordering needs explicitly; unordered by default is safer to assume.
- Include correlation IDs and causation metadata.
Consistency
- Strong consistency has operational cost; use it where business correctness needs it.
- Eventual consistency requires visible user and operator handling.
- If divergence is possible, define reconciliation before shipping.
Sagas and Compensation
- Use compensation when the workflow spans multiple irreversible boundaries.
- Compensation must be explicit, auditable, and tested.
- Never describe a workflow as atomic if it crosses systems that cannot commit atomically.
Deliverables
For distributed-system work, produce:
- service and ownership map
- contract list
- consistency decision table
- event and retry flow notes
- reconciliation or compensation plan
- stuck-workflow and replay detection signals
Review Checklist
References
- references/consistency-decision-matrix.md: How to choose synchronous, asynchronous, strong, or eventual consistency.
- references/messaging-checklist.md: Event, queue, and saga review prompts.
Capability contract
Model boundaries, messages, and failure semantics by default. Do not provision brokers, replay events, or mutate production state unless explicitly authorised.
Degraded mode
If topology or failure evidence is unavailable, return a read-only pattern comparison and assumptions register; withhold recommendations dependent on unknown delivery guarantees.
Domain Anti-Patterns
- Assuming exactly-once delivery. Fix: define idempotency and deduplication.
- Sharing one database across autonomous services. Fix: assign data ownership.
- Publishing before the state change commits. Fix: use a transactional outbox.
- Retrying non-idempotent commands blindly. Fix: add keys and retry limits.
- Omitting poison-message handling. Fix: define dead-letter and replay controls.
1---2name: distributed-systems-patterns3description: Use when designing or reviewing multi-service, message-driven, or eventually consistent systems. Covers service boundaries, consistency tradeoffs, event workflows, outbox and inbox patterns, sagas, ordering, and idempotency.4---56# Distributed Systems Patterns7Acknowledgement: Shared by Peter Bamuhigire, techguypeter.com, +256 784 464178.89<!-- dual-compat-start -->10## Use When1112- Use when designing or reviewing multi-service, message-driven, or eventually consistent systems. Covers service boundaries, consistency tradeoffs, event workflows, outbox and inbox patterns, sagas, ordering, and idempotency.1314## Do Not Use When1516- The change is a single-process transaction with no remote dependency, asynchronous delivery, or independently failing component.17- The task is mainly service decomposition or API shape; use `system-architecture-design` or `api-design-first` and return here for cross-boundary failure semantics.1819## Required Inputs2021| Input | Required | Why it matters |22|---|---|---|23| Workflow steps and system boundaries | yes | Identifies where atomicity ends and partial failure begins |24| Delivery, ordering, and consistency requirements | yes | Determines idempotency, sequencing, and reconciliation choices |25| Failure and recovery expectations | yes | Sets timeout, retry, compensation, and operator intervention rules |26| Throughput and latency constraints | conditional | Tests whether the coordination pattern is viable |2728## Workflow2930Draw state transitions and ownership boundaries, enumerate failure windows, choose consistency and coordination patterns, define idempotency and recovery, then verify duplicate, reordered, delayed, and partially applied events.3132## Quality Standards3334Every remote interaction has a timeout and failure policy. Every retried side effect has an idempotency rule. Consistency claims state their scope, and recovery does not assume exactly-once delivery.3536## Outputs3738| Output | Consumer | Acceptance condition |39|---|---|---|40| Distributed workflow model | Architecture and implementation teams | Shows state ownership, message boundaries, consistency guarantees, and failure windows |41| Failure-handling contract | Service owners | Defines timeout, retry, deduplication, compensation, replay, and reconciliation behavior |42| Verification scenarios | Test and operations teams | Cover duplicates, reordering, concurrency, dependency outage, and partial completion |4344## Evidence Produced4546| Category | Artifact | Format | Example |47|----------|----------|--------|---------|48| Operability | Service consistency and idempotency note | Markdown doc covering chosen consistency model, idempotency keys, and saga sequences | `docs/dist/consistency-note-checkout.md` |49| Operability | Failure-mode catalogue | Markdown doc listing partition, retry, and replay failure modes with mitigations | `docs/dist/failure-modes-checkout.md` |5051## References5253- Use the `references/` directory for deep detail after reading the core workflow below.54- Load `references/event-driven-architecture.md` for event choreography, event contracts, brokers, and asynchronous workflow design.55- Load `references/realtime-systems.md` for WebSocket, SSE, pub/sub, and realtime delivery concerns.56<!-- dual-compat-end -->57Use this skill when a design crosses process, service, queue, or region boundaries. The goal is to keep distributed complexity deliberate and bounded rather than accidental.5859## Load Order60611. Load `world-class-engineering`.622. Load `system-architecture-design` first for the overall shape.633. Load this skill only when the system genuinely needs multiple services, asynchronous workflows, or weakly consistent boundaries.6465## Decision Workflow6667### 1. Justify Distribution6869State why distribution is necessary:7071- team ownership and release independence72- scaling asymmetry73- fault isolation74- compliance or tenancy isolation75- long-running or bursty workflows7677If none of these are strong, prefer a modular monolith.7879### 2. Define Boundaries and Contracts8081For each service or asynchronous component, define:8283- owned data84- API or event contracts85- consistency expectation86- failure effect on upstream and downstream flows87- observability and ownership requirements8889### 3. Choose Interaction Patterns9091Use:9293- synchronous calls when the caller needs immediate confirmation94- messaging when work is slow, bursty, or naturally eventual95- outbox and inbox patterns when reliability across boundaries matters96- sagas or compensations when one business workflow spans multiple durable states9798### 4. Design Consistency and Recovery99100Make explicit:101102- source of truth103- ordering requirements104- deduplication strategy105- reconciliation path106- timeout and retry policy107- compensation or manual repair path108109### 5. Prove the Design110111Before calling it production-ready, provide:112113- consistency model114- failure-mode examples115- idempotency and replay notes116- contract evolution rules117- operational signals for stuck or divergent workflows118119## Non-Negotiable Standards120121### Service Boundaries122123- Each service owns its data and rules.124- Do not share databases across services as a convenience.125- Keep contracts narrow and versionable.126- Avoid chatty request chains on critical paths.127128### Messaging129130- Assume at-least-once delivery unless proven otherwise.131- Design consumers to be idempotent and replay-safe.132- Define ordering needs explicitly; unordered by default is safer to assume.133- Include correlation IDs and causation metadata.134135### Consistency136137- Strong consistency has operational cost; use it where business correctness needs it.138- Eventual consistency requires visible user and operator handling.139- If divergence is possible, define reconciliation before shipping.140141### Sagas and Compensation142143- Use compensation when the workflow spans multiple irreversible boundaries.144- Compensation must be explicit, auditable, and tested.145- Never describe a workflow as atomic if it crosses systems that cannot commit atomically.146147## Deliverables148149For distributed-system work, produce:150151- service and ownership map152- contract list153- consistency decision table154- event and retry flow notes155- reconciliation or compensation plan156- stuck-workflow and replay detection signals157158## Review Checklist159160- [ ] Distribution is justified by real constraints.161- [ ] Data ownership is explicit and not undermined by shared persistence shortcuts.162- [ ] Idempotency and replay behavior are defined.163- [ ] Ordering assumptions are explicit.164- [ ] Consistency and compensation strategy match business risk.165- [ ] Operational detection exists for stuck, duplicated, or divergent workflows.166167## References168169- [references/consistency-decision-matrix.md](references/consistency-decision-matrix.md): How to choose synchronous, asynchronous, strong, or eventual consistency.170- [references/messaging-checklist.md](references/messaging-checklist.md): Event, queue, and saga review prompts.171172## Capability contract173Model boundaries, messages, and failure semantics by default. Do not provision brokers, replay events, or mutate production state unless explicitly authorised.174175## Degraded mode176If topology or failure evidence is unavailable, return a read-only pattern comparison and assumptions register; withhold recommendations dependent on unknown delivery guarantees.177178## Domain Anti-Patterns179- Assuming exactly-once delivery. Fix: define idempotency and deduplication.180- Sharing one database across autonomous services. Fix: assign data ownership.181- Publishing before the state change commits. Fix: use a transactional outbox.182- Retrying non-idempotent commands blindly. Fix: add keys and retry limits.183- Omitting poison-message handling. Fix: define dead-letter and replay controls.