What does eventual consistency mean in Cassandra?
Understand eventual consistency in Cassandra: how replicas converge over time via read repair, hinted handoff and anti-entropy repair, and its CAP trade-offs.
Expected Interview Answer
Eventual consistency means that if no new writes are made, all replicas of a piece of data will converge to the same, most recent value over time, even though they may temporarily disagree right after a write.
Cassandra favors availability and partition tolerance, so a write can succeed before every replica has it. During that window different replicas may return different values, but background mechanisms like read repair, hinted handoff, and anti-entropy repair propagate the latest version until all copies agree. Timestamps resolve conflicts through last-write-wins, guaranteeing convergence rather than instant, cluster-wide agreement.
- High availability even during node or network failures
- Low-latency writes that need not wait for every replica
- Automatic convergence via read repair and anti-entropy
- Partition tolerance without blocking clients
- Scales writes horizontally across many nodes
AI Mentor Explanation
It is like the live score on different apps during a match. The instant a boundary is hit, one app updates immediately while another still shows the old total for a few seconds. Nobody blocks the game waiting for every screen to match; given a moment with no new runs, all the apps settle on the identical correct score.
Step-by-Step Explanation
Step 1
A write reaches some replicas
A write with a low consistency level succeeds after only some of the replicas persist it.
Step 2
Replicas temporarily disagree
Until propagation completes, different replicas may return different values for the same row.
Step 3
Hinted handoff stores missed writes
If a replica is down, the coordinator keeps a hint and replays the write when the node returns.
Step 4
Read repair reconciles on access
When a read detects mismatched replicas, Cassandra pushes the newest version to the stale ones.
Step 5
Anti-entropy repair converges everything
Scheduled repairs compare data via Merkle trees and fix any lingering differences so all replicas match.
What Interviewer Expects
- Correct definition of eventual convergence over time
- Link to the AP side of the CAP theorem
- Mechanisms: read repair, hinted handoff, anti-entropy repair
- Last-write-wins conflict resolution by timestamp
- Awareness that stronger consistency is opt-in via QUORUM
Common Mistakes
- Confusing eventual consistency with permanent inconsistency
- Thinking Cassandra can never be strongly consistent
- Ignoring the repair mechanisms that drive convergence
- Assuming reads always return the latest write
- Not mentioning timestamps and last-write-wins
Best Answer (HR Friendly)
“Eventual consistency means that right after an update, different copies of the data might briefly disagree, but Cassandra keeps working and quietly syncs them so that, given a little time, every copy ends up showing the same latest value.”
Code Example
-- Eventual: fast, may briefly read stale data
CONSISTENCY ONE;
SELECT balance FROM accounts WHERE id = 7;
-- Opt into stronger reads when needed
CONSISTENCY QUORUM;
SELECT balance FROM accounts WHERE id = 7;Follow-up Questions
- How does read repair help achieve convergence?
- What is hinted handoff in Cassandra?
- How does Cassandra resolve write conflicts?
- How does eventual consistency relate to the CAP theorem?
- Can Cassandra provide strong consistency, and how?
MCQ Practice
1. Eventual consistency guarantees that replicas will:
Given no new writes, background mechanisms propagate the latest value until all replicas converge to the same state.
2. Which mechanism repairs stale replicas during a read?
Read repair detects mismatched replicas on a read and pushes the newest version to the stale ones.
Flash Cards
What is eventual consistency? — The guarantee that, absent new writes, all replicas will converge to the same latest value over time.
Which CAP properties does Cassandra favor? — Availability and partition tolerance (AP), trading immediate consistency for uptime.
How are write conflicts resolved? — Last-write-wins based on the cell's timestamp.
Name three convergence mechanisms — Read repair, hinted handoff, and anti-entropy (Merkle-tree) repair.