/designing-data-intensive-applications:consistency-model-selectorfrom designing-data-intensive-applications
Matches each operation in a distributed system to the appropriate consistency model (linearizability, causal, eventual) and implementation mechanism. Produces per-operation recommendations including replication technique, ordering guarantee, and consensus protocol when needed.
Ships in designing-data-intensive-applications. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Use this skill when you need to decide how strongly consistent a distributed operation must be, and what mechanism enforces that guarantee.
Invoke it for:
Do not invoke it for single-node transaction isolation tuning — that is the domain of transaction-isolation-selector.
Before selecting a model, collect the following per operation or component:
replication-strategy-selector)If a codebase is available, search for:
w, r, n)WHY: Different operations have fundamentally different correctness requirements. Over-provisioning consistency wastes latency and availability; under-provisioning introduces bugs that only appear under concurrency or network faults — the hardest class of bugs to detect in testing.
Apply this decision table per operation:
| Scenario | Minimum Required Model |
|---|---|
| Display a user's own recent writes to that same user | Read-your-writes (causal) |
| Show a feed where replies never appear before questions | Causal consistency |
| Enforce a hard uniqueness constraint (username, seat, stock limit) | Linearizability |
| Acquire a distributed lock that prevents split-brain | Linearizability |
| Elect a single leader across nodes | Linearizability (via consensus) |
| Atomically commit a transaction across multiple nodes | Atomic commit (consensus-equivalent) |
| Show analytics dashboard (staleness of seconds acceptable) | Eventual consistency |
| Show a social feed where ordering is approximate | Eventual consistency |
| Replicate writes across datacenters for disaster recovery | Eventual consistency (async replication) |
Key distinction — linearizability vs. serializability (commonly confused):
WHY: Causal consistency is the strongest model that does not slow down under network delays and remains available during network failures. Linearizability is strictly stronger but imposes real latency costs proportional to network uncertainty. Always use the weakest model that is correct.
Eventual consistency — use when:
Causal consistency — use when:
Linearizability — use when:
WHY: Consensus is harder than it looks. Many operations that appear simple are actually reducible to consensus, meaning they require a consensus algorithm to implement correctly in a fault-tolerant way. Identifying this early prevents building brittle custom solutions.
The following 6 problems are all equivalent to consensus — if you need to solve any one of them in a fault-tolerant distributed system, you need a consensus algorithm:
If your operation matches any of the above, evaluate whether to:
WHY: 2PC is the standard algorithm for atomic commit across multiple nodes. It solves a real problem but introduces a single point of failure (the coordinator) and can block indefinitely — understanding its failure modes is essential before choosing it.
How 2PC works:
prepare to all participant nodesyes (promises it can commit) or no (aborts)yes, coordinator writes commit decision to its log (the commit point), then sends commit to all participantsno, coordinator sends abort to all participantsThe critical failure mode — coordinator crash after prepare:
yes, it cannot unilaterally abort or commit — it must wait for the coordinator's decisionyes votes but before sending the commit/abort: participants are in-doubt and blocked indefinitely2PC failure mode catalog:
| Failure | Outcome |
|---|---|
| Coordinator crashes before prepare | Safe: participants can abort |
| Participant crashes before voting | Coordinator aborts on timeout |
| Network partitions participant from coordinator | Coordinator aborts on timeout (before commit point) |
Coordinator crashes after commit point, before all commit sent | Remaining participants are in-doubt; blocked until coordinator recovers |
| Coordinator log lost after crash | Orphaned transactions; manual intervention required |
| Long coordinator restart (e.g., 20 minutes) | All participant locks held for that duration; application may be largely unavailable |
2PC performance cost: Disk fsyncs at each phase, additional network round-trips, lock-holding during coordination. MySQL distributed transactions reported at 10x slower than single-node.
When 2PC is appropriate:
When to avoid 2PC:
Alternatives to 2PC for cross-service correctness:
distributed-failure-analyzer)WHY: Implementing consensus from scratch has a very poor success record. Well-tested consensus systems exist and should be used as building blocks. The key insight is that total order broadcast (the core of Raft, Zab, Paxos) is the practical primitive that enables all 6 consensus-equivalent problems to be solved safely.
Total order broadcast (also called atomic broadcast) provides:
Consensus algorithm selection:
| Algorithm | Implemented by | Notes |
|---|---|---|
| Raft | etcd, CockroachDB, TiKV, Consul | Well-specified, good documentation, widely adopted |
| Zab | ZooKeeper | Total order broadcast directly; basis of Hadoop/HBase/Kafka coordination |
| Multi-Paxos | Google Chubby, Spanner | Highly proven, complex to implement correctly |
| Viewstamped Replication | Basis for VR-based systems | Theoretically important, less common in production |
Do not implement your own consensus algorithm. Use one of the above systems.
ZooKeeper / etcd as outsourced consensus — prefer this model when:
sync() call in ZooKeeper)Fault-tolerant consensus limitations:
WHY: CAP is widely misunderstood. The correct framing is: when a network partition occurs, a linearizable system must choose between staying consistent (refusing requests) or becoming available (serving potentially stale data). This is not a design choice you make once — it is a per-operation consequence of requiring linearizability.
What CAP actually says:
Practical consequence: For each operation you mark as requiring linearizability, document the expected behavior during a partition: error returned, request queued, or application component unavailable. Stakeholders should understand this before the system is deployed.
Scenario: An event ticketing platform lets users book the last seat in a venue. Two users submit requests concurrently.
Trigger: "We're seeing double-bookings in our seat reservation system."
Process:
Output: Linearizability required for the reservation write. Use a single-leader database with serializable isolation for the seat-payment transaction. If cross-database: saga pattern with idempotent payment reversal.
Scenario: A social platform shows threaded comments. Replies should never appear before the question being replied to. Comments can be up to 2 seconds stale. The system uses multi-leader replication across 3 regions.
Trigger: "Users in Asia see replies to questions that haven't appeared yet."
Process:
Output: Causal consistency required for comment ordering. Recommended: single-leader-per-partition with reads from leader. Multi-leader without dependency tracking is not safe for this workload.
Scenario: A distributed job scheduler must have exactly one active scheduler node at a time. If two nodes believe they are the leader, jobs execute twice.
Trigger: "We have a split-brain problem — two scheduler instances both claim leadership and jobs are running twice."
Process:
zxid in ZooKeeper) to prevent a slow previous leader from acting on a stale lock after a new leader is elected.Output: Linearizability required. Use etcd or ZooKeeper for leader election with ephemeral leases and fencing tokens. Never use a custom distributed lock without a consensus-backed service.
Cross-references:
replication-strategy-selector — replication topology must be compatible with the selected consistency modeldistributed-failure-analyzer — for failure mode diagnosis when consistency violations appear in productiontransaction-isolation-selector — for isolation level selection within a single-node or single-leader transaction contextThis skill is licensed under CC-BY-SA-4.0. Source: BookForge — Designing Data-Intensive Applications by Martin Kleppmann.
Install related skills from ClawhHub:
clawhub install bookforge-replication-strategy-selectorclawhub install bookforge-distributed-failure-analyzerOr install the full book set from GitHub: bookforge-skills
references/2pc-failure-modes.md (opens in a new tab)references/cap-theorem-analysis.md (opens in a new tab)references/consensus-equivalence-checklist.md (opens in a new tab)references/consistency-model-spectrum.md (opens in a new tab)references/linearizability-vs-serializability.md (opens in a new tab)references/total-order-broadcast-primitives.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
14 skills in this plugin
/batch-pipeline-designerDesign batch data processing pipelines for large-scale, bounded datasets processed offline. Use when building ETL workflows, processing logs or clickstream data at scale, generating ML feature pipelines or search indexes, or joining two large datasets that cannot fit in memory. Trigger phrases: "design a batch pipeline", "should I use Spark or MapReduce", "how do I join two large datasets", "build an ETL workflow", "process server logs at scale", "how do I handle skewed data in joins", "implement PageRank on a distributed graph", "design an offline processing job". Covers MapReduce vs dataflow engines (Spark, Flink, Tez), three join strategies (sort-merge, broadcast hash, partitioned hash) with selection criteria, graph processing via the Pregel/BSP model, and fault tolerance via materialization vs recomputation. Does not apply to unbounded input streams (see stream-processing-designer) or low-latency OLTP query serving. Produces a pipeline architecture recommendation with engine choice, join strategy, and fault tolerance approach.
/concurrency-anomaly-detectorScan application code, SQL queries, or ORM code for exposure to the 6 database concurrency anomalies and produce a findings report with severity, affected locations, and fix recommendations. Use when: debugging a nondeterministic data corruption or race condition bug under concurrent load; auditing transaction code before deployment or after switching databases (isolation defaults differ across engines); a read-modify-write cycle or check-then-act pattern may be exposed to lost updates or write skew; an aggregate query (COUNT, SUM) guards an INSERT or UPDATE (phantom read exposure); or multiple tables are updated in one transaction without serializable isolation. Distinct from transaction-isolation-selector (which chooses the isolation level) — this skill scans code to find which anomalies existing code is already exposed to. Covers Python, Java, Go, JavaScript, Ruby; raw SQL; ORM code (SQLAlchemy, Hibernate, ActiveRecord, GORM); PostgreSQL, MySQL InnoDB, Oracle, SQL Server, and distributed databases. Maps code patterns (read-modify-write, SELECT/INSERT pairs, cross-table boundaries, snapshot boundary reads) to anomaly type, trigger conditions, and minimum fix (isolation upgrade vs. application-level mitigation).
npx claudepluginhub bookforge-ai/bookforge-skills --plugin designing-data-intensive-applicationsOther plugins' skills for the same job