CMD Guide
HomeSystem DesignCAP Theorem

Examples of CAP Theorem in Practice

Every one of these systems runs the same reflex at its core: when a node cannot reach a majority (a quorum) of its peers, does it keep answering, or does it go silent? That single reflex — wired into the replication protocol, not chosen per request — is what drops a database into the CP or the AP bucket. The previous page named the buckets; this page opens the machine and shows the exact mechanism, with real defaults and a timed trace, so you can predict a system's behaviour under partition instead of memorising a label.

diagram
diagram

CP mechanism: quorum voting and the failover pause

CP systems make the minority side go dark on purpose. The mechanism is a quorum vote — a majority of ⌊N/2⌋ + 1 nodes must agree before any state advances.

Worked trace: a MongoDB failover with real timings

Three-node replica set — primary P, secondaries S1, S2; quorum = 2; defaults electionTimeoutMillis=10000, heartbeats every 2 s; the application writes with w:"majority".

TimeEvent (mechanism)Cluster stateClient write
t = 0.0 sP is partitioned onto the minority side, aloneS1, S2 healthy = 2/3 quorum; P isolatedbuffered by driver (retryable writes)
0–10 sS1, S2 miss P's heartbeats; no primary is reachablecluster is read-only for writesrejected: NotWritablePrimary
t ≈ 10.0 selection timeout fires on S1 → candidate, term++, requests voteselection in progressstill buffered
t ≈ 10.3 sS1 self-votes + S2 grants = 2/3 majority → S1 is PRIMARYnew primary; oplog caught upbuffered write now committed
on rejoinold P sees a higher term → steps down to secondary; any w:1 write it took that never replicated is rolled back to a .bson rollback fileone consistent history, no split-brain

Net effect: a ~10–12 s write outage per failover, but zero divergence. Because the client used w:"majority", every acknowledged write already lived on at least two nodes, so it survives on S1/S2 — nothing acknowledged is lost. That durability guarantee is the whole point of paying the pause.

AP mechanism: leaderless writes, reconcile later

AP systems keep every side writing and repair the mess afterward. There is no leader whose loss stalls the cluster.

When to use which — and what it costs

These four are not interchangeable; each exposes a different knob and charges a different price.

SystemCore knobBehaviour under partitionConflict handling
ZooKeeper / etcdZab/Raft quorum ⌊N/2⌋+1minority halts writesnone needed — one ordered log
MongoDBreplica set + write concern~10–12 s election pause; minority primary self-demotesw:majority durable; w:1 rolled back
Cassandraper-query R, W vs RFall sides keep writing at CL=ONElast-write-wins timestamp + hinted handoff + repair
DynamoDB3-AZ replication + ConsistentReadstays available; strong read hits leader replica (2× RCU)LWW; Global Tables cross-region: eventual (classic MREC) or strong (opt-in MRSC)

Choose ZooKeeper/etcd for coordination — locks, leader election, small linearizable config. It must be CP because two clients disagreeing on "who holds the lock" is a correctness bug. But it is not a database: it holds its dataset in memory and tops out around tens of thousands of writes/s, so never point application data at it.

Choose MongoDB with w:majority when you want a general document store with read-your-writes and can tolerate a brief write pause on failover — order records, user profiles, content. Prefer Cassandra/DynamoDB instead when a 10-second write outage per failover is unacceptable and the data is append-heavy or naturally last-writer-wins (time series, feeds, telemetry, carts). You gain zero-downtime writes and easy multi-region; you pay with lost-update risk and no cross-row transactions.

Choose DynamoDB over self-run Cassandra when you want the AP model without operating repair, compaction, and clock hygiene yourself, and you value the per-region strong-read escape hatch. Prefer Cassandra when you need control over the storage engine, multi-cloud placement, or want to avoid per-request pricing at very high write volume.

Pitfalls

Takeaways


Sources: Gilbert & Lynch, "Brewer's Conjecture and the Feasibility of Consistent, Available, Partition-Tolerant Web Services" (2002); DeCandia et al., "Dynamo: Amazon's Highly Available Key-value Store" (SOSP 2007); Junqueira, Reed & Serafini, "Zab: High-performance broadcast for primary-backup systems" (2011); MongoDB Manual — Replica Set Elections and Write Concern; Apache Cassandra docs — Tunable Consistency, Hinted Handoff, and Repair; AWS DynamoDB Developer Guide — Read Consistency and Global Tables. Re-authored/Deepened for this guide.

🤖 Don't fully get this? Learn it with Claude

Stuck on Examples of CAP Theorem in Practice? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Examples of CAP Theorem in Practice** (System Design) and want to truly understand it. Explain Examples of CAP Theorem in Practice from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Examples of CAP Theorem in Practice** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Examples of CAP Theorem in Practice** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Examples of CAP Theorem in Practice** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes