distributed-consistency
Choose a consistency model for a cross-node operation — strong/eventual/causal, CAP/PACELC trade-off, idempotency + dedup, and when consensus (Raft/quorum) is warranted vs simpler.
- License 许可
- MIT
- 最近更新
- 2026-10-29
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- distributed-consistency
- description
- Choose a consistency model for a cross-node operation — strong/eventual/causal, CAP/PACELC trade-off, idempotency + dedup, and when consensus (Raft/quorum) is warranted vs simpler.
02 资源文件 1
- 参考文档routing.yaml506 B
03 SKILL.md 正文
distributed-consistency
"Consistent" is not one thing. Name the model you need per operation — most need less than strong, a few need more than eventual — and pay only for that.
Mode: analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked [TBD] or [VERIFY], never filled in.
When to use
- A piece of data lives on / is read from more than one node, region, or service, and correctness depends on what readers see.
- Someone proposed a consensus system (Raft/Paxos/quorum) and you need to confirm it's warranted, not cargo-culted.
- A workflow invokes
polymath-architecture:distributed-consistency.
Not this when: the consistency boundary is inside one service's object model — that is aggregate-design. For the messaging mechanics that deliver updates, see event-driven-design.
Inputs
- The operation, its read/write pattern, and the cost of a stale or conflicting read (money? safety? mild annoyance?).
- Latency and availability requirements; single- vs multi-region.
Procedure
- Classify the operation's need: strong/linearizable (a read sees the latest write — uniqueness, balances, locks), causal (reads respect cause→effect order — comments, sessions), or eventual (converges, brief staleness fine — counters, feeds). Most operations are not strong.
- Apply CAP under partition, PACELC otherwise: during a partition, choose consistency or availability; even with no partition, there is a latency↔consistency trade. State which you pick and the business reason.
- For eventual consistency, define convergence: the staleness budget, conflict resolution (last-writer-wins with caution, version vectors, or CRDTs for commutative merges), and read-your-writes if users expect it.
- Make writes idempotent: idempotency keys + dedup so retried/duplicated writes (inevitable in distributed systems) don't double-apply.
- Justify consensus only when needed: leader election, a replicated log, or strict linearizability across nodes warrant Raft/quorum (e.g.
R+W>N). It costs latency and operational complexity — if a single writer or a managed transactional store suffices, prefer that and say so. - Check time assumptions: don't rely on wall-clock ordering across nodes; use logical clocks / versions where ordering matters.
- Name the failure semantics: what a client sees during a partition, a failover, and a conflict.
Output
Consistency decision: refunds across eu + us regions
Operation Model Why weaker won't do
issue refund strong double refund = lost money; single-writer per payment (home region)
refund status read read-your-writes merchant must see the refund they just issued
merchant dashboard eventual (≤ 30 s staleness) aggregate totals; brief lag is fine
CAP/PACELC: partition → refunds for a payment are unavailable outside its home region (C over A);
normal operation → home-region writes pay ~80 ms cross-region latency (PACELC: C over L)
Idempotency: Idempotency-Key per refund request, dedup table keyed (merchant, key), 24 h retention
Conflicts: none for refunds (single writer); dashboard counters converge by recompute, not merge
Consensus: not needed — the managed DB's single-region primary is the serialization point
Client sees: partition → 503 + Retry-After for refund writes in the non-home region; reads stay up
Inline by default; when a workflow step or the user wants it kept, write it to docs/architecture/<slug>-consistency.md (slug from the system or context name, lowercased, non-a-z0-9 runs → -).
Quality bar
- Each operation names exactly one consistency model and why weaker won't do.
- The partition/failover behavior the client sees is stated.
- Consensus is recommended only with a concrete need; otherwise the simpler option is named.
- Writes have an idempotency story — "we'll retry" without dedup is flagged.
04 同仓库更多 Skills
runbook
Write or refresh an operational runbook for an alert/symptom; structured as TL;DR + Pre-checks + Steps + Verification + Rollback + Escalation.
rfc
Draft a lightweight design RFC to docs/rfcs/<slug>.md; Summary, Motivation, Detailed design, Drawbacks, Alternatives, Unresolved questions. A proposal to debate, not a recorded decision (adr).
editorial-pass
Review and tighten prose in a Markdown artifact for a target tone (terse, formal, friendly) without dropping information; preserve quotations and load-bearing constraints.
architecture-review-facilitation
Run an architecture review as a process — entry criteria, reviewer checklist, decision log, and follow-up actions — pairing the design artifact with a red-team pass.
architecture-doc
Write a C4-style architecture document; System Context + Containers (+ Components when interesting) with mermaid diagrams. Describes structure, not a decision (adr) or proposal (rfc).
adr
Write an Architecture Decision Record (Michael Nygard format) to docs/adrs/NNNN-<slug>.md; frontmatter validated by the ADR artifact schema. Records a made decision, not a proposal to debate (rfc).