How does tunable consistency work in Cassandra (consistency levels)?
Learn how Cassandra tunable consistency works: set ONE, QUORUM or ALL per query and use W + R > RF to balance latency, availability and strong consistency.
Expected Interview Answer
Tunable consistency lets you choose, per query, how many replicas must acknowledge a read or write before Cassandra treats it as successful, trading latency and availability against how fresh and agreed-upon the data must be.
Because Cassandra replicates each row to multiple nodes (the replication factor), you set a consistency level such as ONE, QUORUM, LOCAL_QUORUM, or ALL on each operation. A write succeeds once that many replicas persist it, and a read waits for that many replicas to respond. When reads and writes together involve a strict majority (W + R > RF), you get strong consistency; lower levels give lower latency and higher availability but may return stale data.
- Per-query control over the latency vs. consistency trade-off
- Strong consistency achievable via QUORUM reads and writes
- High availability by tolerating some down replicas
- Datacenter-aware levels like LOCAL_QUORUM reduce cross-region latency
- Same data can be read cheaply or strictly depending on the use case
AI Mentor Explanation
Think of confirming a disputed run-out. With consistency level ONE you trust the first umpire who answers and play on quickly, risking an error. With QUORUM you wait for the majority of the umpiring panel, including the third umpire, to agree before the decision stands, so it is far more reliable but takes longer to reach the players.
Step-by-Step Explanation
Step 1
Set the replication factor
Choose how many copies of each row exist per keyspace, e.g. RF=3, which caps the strongest consistency level available.
Step 2
Pick a consistency level per query
Specify ONE, QUORUM, LOCAL_QUORUM, ALL, etc. on each read and write depending on how fresh the data must be.
Step 3
Writes wait for acknowledgements
The coordinator forwards the write to all replicas and returns success once the required number acknowledge it.
Step 4
Reads gather responses
The coordinator queries replicas, waits for the required number, and returns the most recent version by timestamp.
Step 5
Apply the W + R > RF rule
Combine write and read levels so their sum exceeds RF to guarantee a read sees the latest committed write.
What Interviewer Expects
- Definition of consistency levels as a per-query setting
- Relationship between replication factor and consistency
- The W + R > RF strong-consistency formula
- Awareness of latency, availability and staleness trade-offs
- Datacenter-local levels such as LOCAL_QUORUM
Common Mistakes
- Thinking consistency is fixed cluster-wide rather than per query
- Believing QUORUM always means all replicas
- Ignoring that low levels can return stale reads
- Confusing consistency level with replication factor
- Assuming ALL is a good default despite its availability cost
Best Answer (HR Friendly)
“Cassandra lets you decide, for each request, how many copies of the data must agree before it counts as done. You can favor speed by asking just one copy, or favor accuracy by asking a majority, so the same database can be tuned request by request.”
Code Example
-- Fast, may be slightly stale
CONSISTENCY ONE;
SELECT * FROM users WHERE id = 42;
-- Strong consistency when paired with QUORUM writes
CONSISTENCY QUORUM;
INSERT INTO users (id, email) VALUES (42, '[email protected]');
SELECT * FROM users WHERE id = 42;Follow-up Questions
- What is the difference between QUORUM and LOCAL_QUORUM?
- How do you achieve strong consistency in Cassandra?
- What happens if not enough replicas are available for the chosen level?
- How does read repair relate to consistency levels?
- Why might you choose ONE over QUORUM for writes?
MCQ Practice
1. Which combination guarantees strong consistency with RF=3?
QUORUM is 2 of 3 replicas; 2 + 2 = 4 > 3, so W + R > RF and reads always see the latest write.
2. What does consistency level ONE prioritize?
ONE returns as soon as a single replica responds, giving the lowest latency and best availability but possible staleness.
Flash Cards
What is tunable consistency? — The ability to choose, per read or write, how many replicas must respond before Cassandra treats the operation as successful.
Formula for strong consistency — W + R > RF, where W is the write level, R the read level, and RF the replication factor.
What does QUORUM mean? — A strict majority of replicas, i.e. floor(RF/2) + 1 nodes must acknowledge the operation.
Trade-off of consistency level ONE — Lowest latency and highest availability, but reads may return stale data.
Continue Learning
Related Interview Questions
What is the difference between QUORUM and ONE consistency levels?
medium
What does eventual consistency mean in Cassandra?
easy
How do you work out consistency levels across two datacentres so reads see writes without cross-region latency?
hard
What is read repair and how does anti-entropy work in Cassandra?
hard