We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Distributed Systems Core
Free preview: the first 2 parts of this 9-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Distributed Systems Core
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
Hinted handoff handles writes when a node is briefly down. Read repair fixes stale data when someone reads it. But what about the data nobody reads? What about the replica that was down for three days and missed thousands of writes that will never be read again?
That's where anti-entropy comes in. It's the background process that periodically compares every piece of data across replicas, finds differences, and repairs them. If hinted handoff is the first responder and read repair is the opportunistic fixer, anti-entropy is the deep cleaning crew that comes through on weekends and catches everything the others missed.
The challenge is efficiency. You might have billions of keys across your replicas. Comparing them one by one would take forever and consume massive . This is where Merkle trees (hash trees) come in, they let two nodes compare their entire datasets by exchanging just a handful of hashes. If the root hashes match, the datasets are identical. If they differ, the nodes can drill down the tree to find exactly which keys are out of sync, transferring only the data that's actually different.
Cassandra calls this "nodetool repair." DynamoDB runs it automatically in the background. It's the mechanism that guarantees eventually consistent systems actually converge, without it, stale data could persist indefinitely.
A Merkle tree is a binary tree where every leaf node contains the hash of a data block, and every non-leaf node contains the hash of its children's hashes. The root hash is a fingerprint of the entire dataset.
To compare two replicas:
| Comparison Step | Data Exchanged | What We Learn |
|---|---|---|
| Root hashes | 2 hashes | Are replicas identical? |
| Level 1 children | 4 hashes | Which half is different? |
| Level 2 children | Up to 8 hashes | Which quarter is different? |
| ... | ... | Narrowing down |
| Leaf level | Individual key hashes | Exact keys that differ |
For a dataset with 1 billion keys and a tree depth of 30, you might exchange only 60-100 hashes to find 5 differing keys. That's the power of Merkle trees, logarithmic comparison complexity.
Cassandra's approach: Each node builds a Merkle tree per token range per table. During repair, nodes exchange trees for their shared token ranges. Only the keys identified as different are streamed across the network.