Free preview

Permanent Failures: Anti-Entropy with Merkle Trees

Why this matters: hinted handoff covers a node that comes back quickly. This covers a node that comes back a week later, or gets replaced entirely — and it does so without shipping the whole dataset across the network to find out what changed.

Key takeaway

When a node fails and is replaced, or recovers after a long outage, replicas must synchronize to restore durability. Merkle trees detect inconsistencies between replicas and limit data transfer during anti-entropy synchronization.

The structure

A Merkle tree (or hash tree) organizes data hashes hierarchically:

  • Leaves contain hashes of individual key values.
  • Parent nodes contain hashes of their children.

Each leaf H1..H8 is the hash of a key's value (K1..K8); each parent hashes its two children; the root summarizes everything below it.

The essential property: a Merkle tree allows nodes to verify subtrees independently. If the root hashes match, the datasets are identical. If they differ, the nodes recursively compare child hashes to identify the specific key ranges that diverge — without transferring the entire dataset to make the comparison.

Anti-entropy in practice

Each node maintains a Merkle tree for the key ranges it hosts. Because of virtual nodes, that means several trees — one per range:

Node A owns virtual nodes: [N1, N3, N5]
  N1 -> range [r+1, s]
  N3 -> range [m+1, n]
  N5 -> range [o+1, p]

Node B owns virtual nodes: [N2, N4, N6, N7]
  N2 -> range [0, m]
  N4 -> range [n+1, o]
  ...

To synchronize, two nodes exchange the root hashes of their trees:

  1. Compare root hashes. If they match, the data is consistent and no further action is needed.
  2. Traverse the tree. If the hashes differ, recurse down the left and right children.
  3. Synchronize. Identify the specific leaves that differ and transfer only the missing or inconsistent data.

The trade-off

Detail
AdvantageMerkle trees minimize disk I/O and network bandwidth, because only inconsistent data is transferred
DisadvantageWhen a node joins or leaves the system, key ranges change — requiring the tree hashes to be recalculated

Key takeaway

Anti-entropy answers "are these replicas the same?" in one round trip, and "where exactly do they differ?" in logarithmic time. It is what lets a replaced node rejoin without a full data copy.

Interview signal by level

LevelWhat a strong answer sounds like
L4"The nodes compare their data and sync what's different."
L5Names the structure: "Merkle trees — compare root hashes, and only walk down where they differ, so you don't transfer everything."
Staff+Quantifies and connects it: "a root-hash match proves gigabytes are identical in one comparison, and finding a divergence is logarithmic. The cost is that ring membership changes invalidate the trees — which is exactly why failure detection has to be conservative about declaring a node gone."

Next: knowing which nodes are actually there.

Enjoying the preview?

Create a free account to unlock the rest of this course, the in-browser judge, and live AI mock interviews.

Sign up free to continue