Replication and Consistency
Part 2 deliberately pretended each range had one owner. It doesn't — every range is replicated RF times, and that's what keeps a node failure boring. This part is about what replication costs you in exchange: replicas drift, and the mechanisms that pull them back together (quorum overlap, hinted handoff, read repair) each fix a different subset of the drift and leave the rest to a manual nodetool repair. The single most important idea here is that R + W > N is not a transaction — it makes reads fresh without making writes safe.
Replication Factor and Topology
Replication factor (RF) is the number of copies Cassandra maintains for every piece of data. RF=3 means each row exists on 3 different nodes.
RF is set per keyspace — Cassandra's term for a logical database or namespace — not per table.
CREATE KEYSPACE my_app
WITH replication = {
'class': 'NetworkTopologyStrategy',
'us-east': 3,
'eu-west': 2
};Topology Hierarchy: Node, Rack, Datacenter
Cassandra's topology is a strict hierarchy: Data Center → Rack → Node.
| Node | One running instance of the database process — one machine or VM. Owns a range of tokens and stores data on local disk. The smallest unit of topology. |
|---|---|
| Rack | A logical grouping of nodes, typically mapped to a physical rack — shared power, shared top-of-rack switch. Racks matter because everything in one tends to fail together. |
| Data center | A group of racks — usually a distinct facility or cloud region. Used for geographic distribution, workload isolation (analytics vs. live traffic), and disaster recovery. |
Cassandra uses this hierarchy directly in replica placement: RF is specified per datacenter, and within a DC, replicas are spread across racks — so a single node, rack, or DC failure never takes out every copy at once.
Replica Placement Strategies
The placement strategy controls which nodes receive the replicas.
| Strategy | How it places replicas | Use it when |
|---|---|---|
| SimpleStrategy | The next N nodes clockwise on the ring, ignoring rack and datacenter topology entirely | Single-datacenter development clusters. Never production. |
| NetworkTopologyStrategy | RF specified per datacenter; within each DC, replicas are placed on nodes in different racks | Always, in production. With RF=3 and 3 racks, each replica lands in a different rack, so a full rack failure still leaves 2 complete copies. |
- Guarantees: RF distinct nodes hold every row, chosen to spread across racks and datacenters according to the declared topology.
- Does not guarantee: That those nodes are on genuinely independent hardware. Placement is only as good as the labels, and nothing validates them against reality.
R + W > N, Explained Simply
The setup: a row has N copies. When you write, you wait for W of them to confirm. When you read, you ask R of them and go with what they say.
The question the formula answers: how do I pick R and W so a read is guaranteed to see the most recent write?
R + W > N
Concrete example: N=3 replicas (A, B, C), with W=2 and R=2.
- A write might succeed on A and B.
- A read might query B and C.
- Even though the read never asked A, it asked B — and B has the new value. Guaranteed overlap, guaranteed fresh read.
If instead R=1 and W=1 (R+W = 2, not > N = 3), the write could land only on A while the read only checks C. No overlap, stale read possible.
Consistency Levels in These Terms
Cassandra has no setting called "W = 2". Instead, every query gets a named consistency level, and Cassandra turns that name into a number of replicas. That number is your W (on a write) or your R (on a read).
Step 1: what each name means. With 3 copies of every row (RF = 3):
| You put in the query | Cassandra waits for |
|---|---|
ONE | 1 replica |
QUORUM | a majority, which is 2 of 3 (the rule is floor(RF/2)+1) |
ALL | all 3 replicas |
LOCAL_QUORUM | a majority of the copies in your own datacenter: 2 of that DC's 3 |
Step 2: add the write number and the read number. A read is guaranteed to see the latest write only if the two numbers add up to more than 3:
| Write level | Read level | W + R | Fresh read guaranteed? |
|---|---|---|---|
ONE (1) | ONE (1) | 2 | ✗ No. They can hit different replicas. |
ONE (1) | ALL (3) | 4 | ✓ Yes, but every read needs all 3 nodes up |
QUORUM (2) | QUORUM (2) | 4 | ✓ Yes. This is the standard choice. |
ALL (3) | anything (1+) | 4+ | ✓ Yes, but one node down and the write fails |
The datacenter catch. LOCAL_QUORUM only counts replicas in the datacenter you're talking to. Suppose you have two datacenters, DC1 and DC2, each with 3 copies:
- Write in DC1, read in DC1: 2 + 2 > 3 inside DC1, so the read is fresh ✓
- Write in DC1, read in DC2: DC2 gets the write later, in the background. The read might be stale ✗
Consistency levels are just names for R and W. Pick a write level and a read level whose numbers add up to more than RF. In practice that means
QUORUM+QUORUM, orLOCAL_QUORUM+LOCAL_QUORUMwhen the write and the read happen in the same datacenter.
Nothing Above Happens by Default
The overlap guarantee only applies if you ask for it by choosing levels like QUORUM. If you don't choose anything, you get the weakest setting:
| DataStax drivers default to | LOCAL_ONE: ask 1 replica in your datacenter |
|---|---|
cqlsh defaults to | ONE: ask 1 replica |
So out of the box, every write waits for 1 replica and every read asks 1 replica. That's 1 + 1 = 2, which is not more than 3. The read and the write can hit different replicas, and the read can come back stale.
Why not always use QUORUM? Because it costs you something. You choose the level per query, so pick based on what each query needs:
ONE / LOCAL_ONE | QUORUM (RF=3) | |
|---|---|---|
| Replicas it waits for | 1 | 2 |
| Speed | Fast: the quickest replica answers | Slower: it waits for the second replica, so one slow node slows the query down |
| Still works with… | 2 of 3 nodes down | 1 of 3 nodes down. Lose a second one and queries fail. |
| Across datacenters | Stays in your datacenter | May wait on another datacenter (LOCAL_QUORUM doesn't) |
ONE is the right choice when slightly old data is fine and speed matters: analytics, cache refills, view counters. The mistake isn't using ONE. It's using ONE and assuming reads are always fresh.
Most production apps use
LOCAL_QUORUMfor both writes and reads. You get fresh reads inside your datacenter without waiting on a far-away one. PlainQUORUMwould give fresh reads across all datacenters, but then every query waits on a round trip to another region.
"Contacted" Means Something Different for Reads and Writes
That table says QUORUM at RF=3 needs 2 replicas. True for both reads and writes — but the number of nodes the coordinator actually talks to differs, and that difference decides what happens when a replica is unhealthy.
| Write @ QUORUM, RF=3 | sends to all 3, returns as soon as 2 ack |
|---|---|
| Read @ QUORUM, RF=3 | sends to exactly 2, needs both to answer |
Writes are broadcast because a mutation is small and idempotent — sending a third copy costs almost nothing and the redundancy is free insurance. Reads are not: a data response can be megabytes, so contacting replicas you don't need would waste bandwidth on every single query.
Digest Reads: Why Two Replicas Isn't Two Copies of the Data
At QUORUM the coordinator (the node that received your query) needs answers from 2 replicas. But the two copies are almost always identical, so getting the full rows from both would waste bandwidth. Instead, only one replica sends the real data and the other sends a fingerprint:
- The fastest replica sends the full data. Cassandra keeps track of how quickly each replica has answered lately; this tracker is called the dynamic snitch. A node that's slow right now (busy compacting, stuck in a garbage-collection pause, on a slow disk) scores worse. The coordinator asks the best-scoring replica for the actual rows.
- The other replica sends only a fingerprint. It runs the same query but returns a digest: a short hash of the result, a few bytes instead of the whole payload.
- Fingerprints match: both copies agree, so the coordinator returns the data it already has. This is what happens almost every time.
- Fingerprints don't match: one copy is out of date. Only then does the coordinator fetch the full data from the other replica too, keep the version with the newest timestamp, and fix the stale copy (read repair, §5).
So a normal QUORUM read sends one copy of the data plus one tiny hash over the network, not two copies. It's also how Cassandra notices that replicas disagree in the first place: read repair in §5 starts from a fingerprint mismatch.
Speculative Retry: What Saves a Read When a Replica Goes Quiet
Asking only 2 replicas saves bandwidth, but there's a catch. The coordinator needs both answers, and no backup request is already on its way. If one of the two is slow, or has died and nobody has noticed yet, the read just sits there waiting.
Speculative retry is the fix: if a replica takes longer than usual to answer, the coordinator sends the same request to the third replica, the one it didn't ask.
What "longer than usual" means. Each table has a speculative_retry setting. The default is 99PERCENTILE: if a replica is slower than 99% of this table's recent reads, try another one. That kicks in after a few milliseconds, long before the 5-second timeout. The third replica answers, the coordinator has its 2 responses, and the client sees a slightly slow read instead of an error.
That's why losing a node usually shows up on dashboards as a brief p99 latency spike, not a wave of failed reads.
| If a replica is dead and… | What happens to the QUORUM read |
|---|---|
| …it wasn't one of the 2 asked | Nothing. Normal speed, correct answer. |
| …it was asked, and a third replica is available | Speculative retry asks the third one. The read succeeds, just a bit slower. |
…it was asked, and there's no spare to try (reading at ALL, RF=2, or speculative_retry: NONE) | The read waits the full 5 seconds (read_request_timeout), then fails with ReadTimeoutException. |
This is also why ALL can't survive a dead node on reads, not just on writes. It already asks every replica, so there's no spare left for speculative retry to try.
Putting It Together: One QUORUM Read, Start to Finish
Here are all the pieces above, in the order they happen. The example: RF=3, replicas A, B and C, reading at QUORUM (needs 2 answers).
- The client sends the read to one node. That node is the coordinator for this request. Smart ("token-aware") drivers usually send it straight to a node that holds the data, which saves a network hop.
- The coordinator works out where the row lives. It hashes the partition key and looks it up on the ring: this row lives on A, B and C.
-
It skips replicas it thinks are down. That's based on its own gossip view, not a cluster-wide vote. If fewer than 2 are left, it fails right away with
UnavailableExceptionand sends nothing. - It picks just 2 replicas, not all 3. The dynamic snitch ranks them by recent speed. Say A is fastest, then B. C isn't asked.
- A sends the data, B sends a fingerprint. A returns the actual rows. B runs the same query and returns only a hash.
- Each replica reads from its own storage. Memtable, caches, bloom filters, SSTables: how a single node reads is covered in Part 5.
-
If A or B is slow, it asks C. If one hasn't answered by the
speculative_retrythreshold, the coordinator sends the same request to C. This is the only time C hears about this read. If there still aren't 2 answers after 5 seconds (read_request_timeout), the read fails withReadTimeoutException. - It compares the two answers. If the fingerprint matches the data, it returns the data. This is almost always what happens.
- If they don't match, it fixes things first. It fetches the full data from both replicas, keeps the newest value for each cell (by timestamp), writes that value back to the stale replica (read repair, §5), and returns it to the client.
The key difference: a write goes to all 3 replicas and waits for enough of them to confirm. A read goes to only as many replicas as it needs, and reaches the third one only through speculative retry. That one difference explains most of how reads and writes behave when a node fails.
What the Formula Does NOT Protect You From
R + W > N guarantees one thing: once a write has succeeded, a later read will see it. It does not cover:
- Two writes at the same time. If two clients write the same row at nearly the same moment, the formula doesn't say which should win, and both can be told "success".
- Wrong clocks. Cassandra picks the "latest" write by its timestamp (last-write-wins). If one server's clock runs ahead, an older write can beat a newer one.
- Transactions. You can't safely read a value, decide something, and write it back. Nothing locks the row between your read and your write.
R + W > N means "a read will see any write that already finished". It isn't a transaction, and it doesn't settle races.
- Guarantees: Once a write has succeeded at W, any read at R asks at least one replica that has it. A finished write never disappears from reads.
- Does not guarantee: Anything about writes still in progress, which of two simultaneous writes wins, or whether the timestamps used to decide are correct.
Walkthrough: What Divergence Actually Looks Like
Case 1: One Replica Misses the Write
Setup: replicas A, B and C. RF=3, writes and reads both at QUORUM (2).
- The client sends a write. The coordinator sends it to A, B and C.
- C goes down before the write reaches it. A and B save it.
- The coordinator has 2 confirmations, which is enough for
QUORUM. It tells the client "success". - Later, a
QUORUMread asks 2 of the 3 replicas.
- Read asks A and B: both have the new value. Correct.
- Read asks A and C (C is back but hasn't caught up yet): one new value, one old. Cassandra returns the one with the newer timestamp, so the answer is correct. But it only works because the old value carries an older timestamp.
Case 2: Two Writes Race Each Other
In Case 1, C just missed one write. A more realistic problem: two clients write the same row at almost the same time, and each write reaches a different pair of replicas.
Readers are fine. Every QUORUM read asks 2 replicas, so it always hits B or C, and both hold "offline", the newer value. Every read returns the same answer.
A still holds the old "online" while B and C hold "offline". Fixing that kind of mismatch is the job of repair. The next two sections cover two cheaper mechanisms that fix some of it first.
- Guarantees: In both cases, every
QUORUMread returns the value with the newest timestamp. Readers never see the replicas disagree. - Does not guarantee: That a successful write will survive, or that anyone is told when it doesn't. There is no conflict warning of any kind.
Hinted Handoff
When replica C is down, the coordinator saves a hint: a small note that says "here's a write C missed, give it to C when it's back." When C returns, the node holding the hint sends C those missed writes, and C catches up without a full repair.
How the Coordinator Knows C Is Down
Nobody announces it. Nodes constantly pass heartbeats around through gossip (Part 2 §5). Each node watches those heartbeats on its own and keeps a suspicion score for every other node (the Phi Accrual failure detector). When C's score passes phi_convict_threshold (default 8, about 10 seconds of silence on a healthy network), that node marks C as DOWN, in its own view only. There's no cluster-wide vote, so two coordinators can briefly disagree about whether C is up.
What the coordinator believes when the write arrives decides what it does:
| The coordinator thinks C is… | What happens |
|---|---|
DOWN | It doesn't send the write to C. It saves a hint right away. |
UP, but C is actually dead (not noticed yet) | It sends the write, C never confirms, and when write_request_timeout runs out it saves a hint anyway. |
| (Too few replicas are up for the consistency level) | It fails right away with UnavailableException. Nothing is written, and no hint is saved. |
So slow failure detection doesn't leave a gap on its own: even if gossip still thinks C is alive, the timeout catches the missed write and a hint is saved. Delivery works the same way in reverse. Once C's heartbeats come back and gossip marks it UP, every node holding hints for C starts sending them.
When Hints Don't Save You
Hints are best-effort. There are real ways C can end up missing data with nothing queued to fix it:
- The coordinator dies. Hints are stored only on the coordinator's own disk, with no copies. If it crashes before saving or delivering them, they're gone.
- C is down too long. Once C has been down longer than
max_hint_window(3 hours by default), coordinators stop saving hints for it. Every write after that is simply missed. - Hints get thrown away. Hints are turned off (
hinted_handoff_enabled: false), hint storage is full, or the hints are older than the table'sgc_grace_seconds. (That age limit exists so an old hint can never bring a deleted row back.) - C is still catching up. C is marked
UPand answering reads while it's still working through its backlog of hints, so for a while it's online but behind.
That's why hints are only the first of three safety nets:
- Quorum (§2): the write still reached enough other replicas, so a
QUORUMread will hit at least one up-to-date copy. - Read repair (§5): fixes stale copies of rows that get read.
- Scheduled
nodetool repair: the only thing that guarantees C eventually has everything.
| Default hint window | 3 hours (max_hint_window_in_ms) |
|---|---|
| After the window | no more hints are saved, and nothing shows the gap |
| The only fix after that | run nodetool repair |
- Guarantees: A replica that comes back within the hint window catches up on the writes it missed, without anyone doing anything.
- Does not guarantee: Anything after the window, or for hints held by a coordinator that itself failed. Hints are a convenience, not a way to keep data safe.
Read Repair
During a QUORUM read, the fingerprints sometimes don't match. Maybe a replica missed a write, or came back before its hints finished arriving. When that happens, the coordinator fetches the full data from the replicas it asked and keeps the value with the newest timestamp (last-write-wins). It returns that value to the client and also writes it back to any replica that had an old copy. That's read repair.
Foreground read repair
Happens when the read already asks more than one replica (QUORUM, ALL, and so on). The coordinator already has both answers in hand, so it compares them on the spot.
Background read repair
For a small, random share of reads, even LOCAL_ONE ones, the coordinator also checked the other replicas behind the scenes. Controlled by read_repair_chance. (Removed in 4.0, see below.)
Why the background version existed: a LOCAL_ONE read asks only one replica, so there's nothing to compare against and foreground repair can never happen. The background version meant even those cheap reads got checked now and then, instead of letting replicas drift apart forever.
Across many requests, this randomly checked a small share of cheap reads. The cost of checking was spread out over time instead of being added to every read.
On 4.0+, a LOCAL_ONE Read Fixes Nothing
That version note matters a lot, because LOCAL_ONE is the driver default.
Before 4.0, a LOCAL_ONE read still helped a little: thanks to read_repair_chance, some of those reads checked the other replicas in the background. On 4.0 and later that's gone. A LOCAL_ONE read asks one replica, returns whatever it says, and fixes nothing.
On 4.0+, reading at
LOCAL_ONEdoesn't just give up the fresh-read guarantee for that query. The read also does nothing to bring replicas back in sync.
Put that next to the other two mechanisms in this part:
| Mechanism | What it fixes | Does it help if you only read at LOCAL_ONE? |
|---|---|---|
| Hinted handoff (§4) | Writes missed during a short outage | Yes, but only within the 3-hour window, and only if the coordinator holding the hint survives |
| Read repair (§5) | Stale copies of rows that get read | No. On 4.0+ it never runs for single-replica reads |
nodetool repair | Everything, including data nobody reads | Yes, but only when someone runs it |
So if a 4.0+ cluster only ever reads at LOCAL_ONE, there are just two ways replicas get back in sync: hints (which expire after 3 hours and vanish if their coordinator dies) and scheduled repair. If repair isn't actually scheduled and finishing, replicas drift apart and every read is a coin flip over which copy you get.
- Guarantees: Any row read from more than one replica gets its stale copies fixed as a side effect.
- Does not guarantee: Full coverage. What gets fixed depends entirely on what gets read, so the least-read data, usually the oldest and most out of sync, gets fixed last or never.
What "Eventual Consistency" Actually Means Here
| What people often assume | What it actually means |
|---|---|
| "My write will be visible everywhere within a few milliseconds." | Cassandra makes no promise about how long it takes. Usually it's under a second, but nothing guarantees that. |
Cases where "eventually" can mean never:
- A node that was down for 4 hours, past the hint window, won't catch up until someone runs repair (§4).
- A row that's never read never gets read-repaired (§5).
- When two writes race, the newest timestamp wins. If a clock is wrong, an older write can permanently replace a newer one (§3).
Eventual consistency means "replicas will end up agreeing, given enough time and no new writes." It says nothing about how long that takes, or whether racing writes end up correct.
The takeaway from this part: there are two kinds of promises. A liveness promise says something good will eventually happen. A safety promise says something bad will never happen. Cassandra's default model gives you the first, not the second. That's fine, as long as your app isn't secretly counting on the second.
- Guarantees: Replicas eventually agree on data that gets read or repaired, as long as writes stop and repair actually runs.
- Does not guarantee: A deadline, correct results when writes race, or that anyone is ever told about a conflict.