awesome-everything RU
↑ Back to the climb

Distributed Systems

CAP in practice: config and scenario reading

Crux Read real configs, query options, and a partition scenario; predict the CP/AP behaviour and consistency guarantee each one actually buys.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 14 min

CAP/PACELC choices are not abstract — they live in consistency levels, write concerns, and quorum settings. Read each config, then predict how it actually behaves when a partition hits.

Goal

Practise the move you make in every design review: translate a consistency-level or quorum config into its concrete CP/AP behaviour and the exact guarantee it gives a reader during a partition.

Snippet 1 — Cassandra tunable consistency

-- N = 3 replicas per key (replication factor 3)
CONSISTENCY QUORUM;  -- W and R each require 2 of 3 acks
INSERT INTO orders (id, total) VALUES (?, ?);
SELECT total FROM orders WHERE id = ?;
Quiz

With RF=3 and QUORUM (W=2, R=2), what guarantee does W+R > N give, and how does a partition change the system's stance?

Snippet 2 — MongoDB write/read concern

db.accounts.updateOne(
  { _id: id },
  { $inc: { balance: -100 } },
  { writeConcern: { w: 1 } }          // ack from primary only
);
// elsewhere, a reporting service:
db.accounts.find({ _id: id }).readPreference("secondaryPreferred");
Quiz

What consistency hazard does this pairing create, and what is the highest-leverage fix?

Snippet 3 — partition scenario log

12:00:01  region=us-east  PUT cart/42  -> 200 OK   (local write accepted)
12:00:01  region=eu-west  PUT cart/42  -> 200 OK   (local write accepted)
12:00:02  link us-east<->eu-west: 100% packet loss (partition)
12:03:10  link restored; anti-entropy reconciliation begins
12:03:10  cart/42 has two divergent versions, equal vector-clock siblings
Quiz

Both PUTs returned 200 during the partition. What does that tell you about the store, and what must happen at reconciliation time?

Snippet 4 — Raft/etcd quorum config

# 3-node etcd cluster, one node in a remote DC
cluster:
  - { name: n1, dc: primary }
  - { name: n2, dc: primary }
  - { name: n3, dc: remote }   # high-latency link to primary DC
election-timeout: 1000ms
heartbeat-interval: 100ms
Quiz

The remote link to n3 frequently spikes above 1000 ms RTT. What failure mode does this configuration invite, and what is the fix?

Recap

Every CAP/PACELC decision shows up as a knob: W+R > N buys read-your-writes overlap but turns CP under partition; w:1 plus secondary reads quietly opts out of durability and freshness; two 200s during a partition are an AP signature whose siblings need a real merge, not LWW; and a Raft election timeout below worst-case RTT manufactures logical partitions. Read the config, name the guarantee it actually gives, then check how it degrades when the link breaks.

Continue the climb ↑CAP in practice: build and partition a replicated store
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.