- 2073 Bhadra · 5 marks
Eventual and tunable consistency in Cassandra
Short answer
Cassandra provides eventual consistency, meaning all replicas eventually converge via hinted handoff, read repair, and anti-entropy, allowing momentary stale reads. Tunable consistency lets clients set per-operation consistency levels (e.g., ONE, QUORUM); strong consistency requires read_replicas + write_replicas > replication_factor.
Explain eventual consistency and tunable consistency in context of Cassandra.
Apache Cassandra is a distributed, masterless, column-family NoSQL database. Data is replicated on several nodes (replication factor N). It is an AP system by default: it favours availability and partition tolerance, and gives consistency that is adjustable.
Eventual consistency
Eventual consistency means that if no new updates are made, all replicas of a data item will eventually become identical, though for a short time different replicas may return different values. A write is accepted by some replicas and propagated to the others in the background. Cassandra repairs differences using:
- Hinted handoff: if a replica is down, another node stores a hint and delivers the write when the replica returns.
- Read repair: during a read, if replicas return different values, the newest (by timestamp) is written to the stale ones.
- Anti-entropy repair: periodic comparison of replicas using Merkle trees.
This gives high availability and low latency, at the cost of possibly reading stale data for a brief time.
Tunable consistency
Cassandra lets the client choose, per read or write operation, how many replicas must respond before the operation is considered successful. This is the consistency level (CL). The user trades consistency for availability and speed.
| Level | Meaning |
|---|---|
| ONE | One replica must acknowledge. Fastest, least consistent |
| QUORUM | Majority of replicas: floor(N/2)+1 |
| ALL | All replicas. Strongest, least available |
| LOCAL_QUORUM | Quorum within the local data center |
| ANY | (writes) even a hint is enough |
Rule for strong consistency: if R + W > N (R = replicas read, W = replicas written, N = replication factor), a read always sees the latest write.
Example: N = 3. Writing with QUORUM (W = 2) and reading with QUORUM (R = 2) gives 2 + 2 = 4 > 3, so reads are strongly consistent. Writing and reading with ONE (1 + 1 = 2 < 3) is fast but only eventually consistent.
Client --write(CL=QUORUM)--> Coordinator
replicas: R1(ack) R2(ack) R3(later)
success after 2 acks; R3 updated eventually
✓ Answer checked by Claude Opus 5.5 (high effort)