Intuition What this page is for
The parent note gave you the four families and the CAP/quorum rules. This page stress-tests that
knowledge by walking through every kind of scenario a problem can throw at you: which database to
pick, every quorum sign, the degenerate cases (one replica, all replicas), the limiting cases
(partition present vs absent), a real-world word problem, and an exam-style trap.
By the end there is no cell of the matrix you haven't seen worked out .
This deep dive lives under the NoSQL parent note . If any term here feels new, the parent built it first.
Before working examples, let us enumerate every case class this topic can produce. Think of it
like listing all quadrants before doing trigonometry — we want zero surprises.
Cell
Case class
What makes it tricky
Worked in
A
Access-pattern → pick a family
matching the query shape to the model
Ex 1, Ex 2
B
Quorum, strong-read region (W + R > N )
the "safe" sign of the inequality
Ex 3
C
Quorum, eventual region (W + R ≤ N )
the "unsafe" sign — reads may miss writes
Ex 4
D
Quorum degenerate: W = N or R = N
one side does all replicas
Ex 5
E
Quorum degenerate: W = 1 , R = 1
the minimum-cost extreme
Ex 4
F
CAP limiting case: partition PRESENT
forced CP-vs-AP choice
Ex 6
G
CAP limiting case: partition ABSENT
you can have both C and A
Ex 6
H
Real-world word problem (multi-system)
combine several families in one app
Ex 7
I
Exam twist / trap
the "obvious" answer is wrong
Ex 8
We treat the quorum inequality like a number line: the sign of W + R − N is the whole story. Positive → strong, zero-or-negative → eventual. Every quorum example below is chosen to hit a different sign or a boundary of that line.
Worked example Ex 1 — Fetch-by-single-key (Cell A)
Statement: A web app stores login sessions. Every request arrives with a session token and needs
the user's session blob back in microseconds , expiring after 1 hour. Which family?
Forecast: Guess before reading — which of the four?
Identify the access pattern. Why this step? The family is chosen by how you read, not by
what the data "is". Here we always read by one known key (the token).
Match to model. Why? A single-key lookup needs no query engine — a hash map gives
average O ( 1 ) . That is exactly key-value → Redis .
Check the extras. Why? We need expiry and speed. Redis has TTL (EX 3600) and lives in RAM.
Answer: Redis (key-value).
Verify: Does the shape fit? "Read by exact key, no filtering, no joins, needs TTL + microsecond
latency" — every requirement maps onto a key-value feature. See Caching Strategies . ✓
Worked example Ex 2 — Relationship-heavy traversal (Cell A)
Statement: "Which accounts share a phone number AND a device AND transact within a fraud ring up
to 4 hops deep?" Which family, and why not SQL?
Forecast: Depth-4 relationships... which model makes a hop cheap?
Name the operation. Why? The core cost is traversing edges to a depth . That is graph traversal .
Cost in SQL. Why? SQL needs one self-JOIN per hop . If each account links to k others,
4 hops cost roughly k 4 index lookups — it explodes with depth .
Cost in a graph DB. Why? Each node stores direct pointers to neighbours ("index-free
adjacency"), so one hop is O ( 1 ) regardless of total graph size .
Answer: Neo4j (graph).
Verify (limiting case): at depth 1 both look similar; the gap only appears as depth grows — which
matches "explodes with depth". At k = 10 , depth 4: SQL touches ≈ 1 0 4 = 10000 rows per seed
vs the graph walking only the edges that actually exist. ✓
Recall the parent's rule: with N replicas, write-acks W , read-nodes R ,
W + R > N ⇒ a read is guaranteed to see the latest write.
The reason is pigeonhole: the R read nodes and W write nodes overlap in at least W + R − N nodes.
We now walk the sign of W + R − N across all its cases.
Worked example Ex 3 — Strong region, positive sign (Cell B)
Statement: N = 5 . You want strong consistency while keeping writes cheap. Pick W , R .
Forecast: You need W + R > 5 . What's the cheapest write side?
Write the inequality. Why? Strong ⇔ W + R > N = 5 , i.e. W + R ≥ 6 .
Minimise W . Why? Cheap writes mean small W . Try W = 2 : then R ≥ 4 .
State the pair. W = 2 , R = 4 gives W + R = 6 > 5 . Overlap = W + R − N = 6 − 5 = 1 node. ✓
Answer: W = 2 , R = 4 (overlap 1). Reads are pricier, writes cheap — a valid tradeoff.
Verify: 2 + 4 = 6 , and 6 > 5 true; overlap = 6 − 5 = 1 ≥ 1 so at least one read node holds the newest
value. ✓
Worked example Ex 4 — Eventual region + minimum extreme (Cells C & E)
Statement: N = 3 , you set W = 1 , R = 1 for maximum speed. Is a read guaranteed fresh? What is the
minimum R that fixes it while keeping W = 1 ?
Forecast: W + R = 2 vs N = 3 — which side of the line?
Compute the sign. Why? W + R − N = 1 + 1 − 3 = − 1 < 0 . Negative ⇒ eventual , not strong.
Interpret. Why? Overlap could be 0 : the one node you write and the one you read may be
different replicas, so a read can miss a just-written value. This is the W = 1 , R = 1 extreme (Cell E).
Repair keeping W = 1 . Why? Need 1 + R > 3 ⇒ R > 2 ⇒ R = 3 . So read all replicas.
Answer: W = 1 , R = 1 is eventual (sign − 1 ); minimum fresh-guaranteeing read is R = 3 .
Verify: 1 + 1 = 2 > 3 (eventual confirmed). 1 + 3 = 4 > 3 (strong confirmed), overlap = 4 − 3 = 1 . ✓
See BASE vs ACID for why eventual is a deliberate choice, not corruption.
Worked example Ex 5 — Degenerate: one side does ALL replicas (Cell D)
Statement: N = 3 . Compare W = 3 , R = 1 against W = 1 , R = 3 . Are both strong? What does each cost?
Forecast: Both sum to 4 > 3 — but who pays?
Check both signs. Why? 3 + 1 = 4 > 3 and 1 + 3 = 4 > 3 — both strong .
W = 3 , R = 1 . Why note it? Every write waits for all replicas → slow/fragile writes (if one
replica is down, no write succeeds), but reads are cheapest.
W = 1 , R = 3 . Why note it? Mirror image: writes cheapest, but every read waits for all replicas.
Answer: Both strong; W = N = write-heavy cost, R = N = read-heavy cost. Pick by your read/write
ratio.
Verify: 3 + 1 = 4 > 3 ✓ and 1 + 3 = 4 > 3 ✓. Both overlaps = 4 − 3 = 1 ≥ 1 . ✓
Worked example Ex 6 — Partition present vs absent (Cells F & G)
Statement: A store with N = 2 data centres. (a) A cable is cut between them; a client writes
v n e w to DC-1, another client reads from DC-2. What can DC-2 do? (b) The cable is fine — can you
have both C and A?
Forecast: During the cut, can DC-2 ever return v n e w ?
State the partition. Why? With the link down, DC-2 cannot learn v n e w (Cell F).
Enumerate DC-2's only two moves. Why? There is no third option:
Return its stale v o l d → Available but not Consistent (an AP system).
Refuse / error out → Consistent but not Available (a CP system).
Formal statement. Partition ⇒ ¬ ( C ∧ A ) — you get at most one.
No partition (Cell G). Why different? Link up ⇒ DC-2 can fetch v n e w , so it answers
and answers correctly → both C and A are possible. CAP only forces a choice during a partition.
Answer: (a) DC-2 must choose AP (stale answer) or CP (refuse). (b) Yes — with no partition you
keep both.
Verify: The logic P ⇒ ¬ ( C ∧ A ) is a truth-table fact: if P true then
( C ∧ A ) must be false. When P false the implication says nothing, so C ∧ A may be true. ✓
See CAP Theorem and Sharding and Replication .
Worked example Ex 7 — One app, four families (Cell H)
Statement: Design storage for a food-delivery app with: (i) live driver-location updates at huge
write rate, (ii) restaurant menus where each cuisine has different fields, (iii) the shopping cart
fetched by session, (iv) "customers who ordered X also ordered Y".
Forecast: Match each sub-system to a family before reading.
Driver locations → Cassandra. Why? Append-only, write-heavy, time-series, partition by
driver_id and cluster by ts → LSM wide-column. (Cell A, write-scale.)
Menus → MongoDB. Why? Varying attributes per document (pizza has crust, sushi has
fish_type) → schema-flexible documents; one read returns the whole menu.
Cart → Redis. Why? Single-key, ephemeral, microsecond reads with TTL.
Recommendations → Neo4j. Why? (customer)-[:ORDERED]->(item)<-[:ORDERED]-(other) is pure
traversal.
Answer: Cassandra + MongoDB + Redis + Neo4j — one family per access pattern. This is polyglot
persistence .
Verify (sanity): each sub-system's dominant query shape (write-stream / flexible-doc / by-key /
traversal) uniquely selects one family with no overlap. ✓
Worked example Ex 8 — The trap: "no schema, so no design" (Cell I)
Statement: A student stores an event log in Cassandra with
PRIMARY KEY (event_id) (a random UUID per event), planning to later run
"give me all events for user_42 sorted by time." Will it work efficiently? If not, fix it.
Forecast: Feels fine — it's "schema-free NoSQL", right?
Spot the assumed capability. Why? The plan needs to filter by user_id and sort by time
— but the partition key is a random event_id, so rows scatter across all nodes.
Why it fails. Why? Cassandra has no joins and no ad-hoc filtering across partitions ;
querying by a non-key column forces an ALLOW FILTERING full scan — an O ( N ) crawl. The "schema
moves to your queries" — you must design the table around the read.
Fix it. Why? Make the query the key:
PRIMARY KEY ((user_id), ts) — partition by user_id (co-locates a user's events on one node),
cluster by ts (pre-sorted by time).
Answer: The original design is a trap — "schema-flexible ≠ schema-free". Correct table:
partition key user_id, clustering key ts.
Verify (against parent): matches the parent's rule "design the table around the query you will
run"; the fixed key gives the exact WHERE user_id=? ORDER BY ts the app needs, on one partition. ✓
Recall Sign-of-quorum cheat sheet
W + R > N means what for reads? ::: A read is guaranteed to see the latest write (strong) — overlap ≥ 1 .
W + R ≤ N means what? ::: Reads may miss a fresh write (eventual); overlap can be 0 .
For N = 3 , is W = 1 , R = 1 strong or eventual? ::: Eventual (1 + 1 = 2 > 3 ).
During a partition, the real choice is between? ::: CP (refuse to stay consistent) vs AP (answer stale to stay available).
Why can't W = N always be used? ::: A single down replica blocks every write — no write-availability.
Mnemonic Picking a family in one breath
K ey → Redis, D ocument-shaped → Mongo, W rite-flood → Cassandra, R elationships → Neo4j.
"K ids D on't W ant R ows."