Cassandra Consistency Levels
Cassandra's most powerful feature is tunable consistency -- you choose per-query how many replicas must participate before an operation is considered successful.
Write consistency levels
| Level | Nodes that must acknowledge | Trade-off |
|---|---|---|
| ONE / TWO / THREE | The specified count | Fast, lower durability |
| QUORUM | Majority (N/2 + 1) | Balanced -- strong consistency when paired with QUORUM reads |
| ALL | Every replica | Highest consistency, lowest availability |
| LOCAL_QUORUM | Majority in coordinator's DC | Strong consistency within one DC; doesn't wait for remote DCs |
| EACH_QUORUM | Majority in every DC | Strongest multi-DC guarantee; highest latency |
| ANY | At least one node (including hinted handoff) | Fastest but weakest -- data may be invisible until hints are delivered |
The coordinator contacts all replicas regardless of consistency level. The write is acknowledged when enough confirm. The rest receive the write asynchronously.
Hinted handoff in Cassandra
When a replica is down, the coordinator stores a hint -- the data plus the target node's identity. When the target recovers (detected via gossip), the hint is forwarded. See Hinted Handoff for the general pattern.
Cassandra-specific details:
- Hints expire after 3 hours (configurable). After that, stale data must be repaired via read repair or
nodetool repair. - With
ANY, a write can succeed by storing only hints -- no replica has the actual data until one recovers. - Hint delivery is throttled to prevent overwhelming recovering nodes.
ANY can lose data if the coordinator dies before delivering hints. Use it only for non-critical, high-throughput writes where occasional loss is acceptable.
Read consistency levels
Read consistency mirrors write levels (except EACH_QUORUM, which is too expensive for reads). The coordinator waits for the specified number of replicas before returning data.
Strong consistency formula: R + W > N guarantees every read sees the latest write. Common config: QUORUM reads + QUORUM writes with N=3 gives R=2, W=2 → 2+2 > 3 ✓
The Snitch: routing reads intelligently
The Snitch determines node proximity and latency. For reads, the coordinator uses it to:
- Send the full data request to the fastest replica
- Send digest requests (checksum only) to other replicas needed for the consistency level
If digests don't match, replicas are out of sync. The coordinator reads full data from all replicas, returns the latest to the client, and triggers read repair.
Read repair in Cassandra
- At
ALL: read repair runs on every read - Below
ALL: runs probabilistically (10% of reads by default) to limit performance impact - Repair is asynchronous -- the client gets its response immediately
Present the R + W > N formula, show how different consistency combinations achieve different guarantees, then mention read repair as the mechanism that gradually fixes inconsistencies. This shows you understand both the theoretical guarantee and the practical repair mechanism.