End-to-End Integrity and Merkle Trees
Overview
A check on a single link or disk protects only that one hop, so integrity has to be checked end to end. And when two replicas hold huge datasets, Merkle trees let them find exactly what differs without sending everything.
Detailed Notes
What is end-to-end integrity
End-to-end integrity means computing the checksum where data is created, carrying it along, and verifying it where the data is finally used (plus at important points in between).
The problem it solves
A user uploads a 2 GB video through a browser, a load balancer, an upload service and finally three disk replicas. Network and disk each have their own checks, yet a faulty memory module in the upload service flips a bit as the bytes pass through its RAM. Every lower-level check later passes, because they were computed after the flip.
If the browser had hashed the whole file and the storage service verified it after writing, the mismatch would be caught. Only the endpoints can verify everything in between. This is the end-to-end principle.
A second problem: two replicas each hold millions of records. Are they identical? Sending all the data to compare would be enormous.
How it works
Layers of built-in checks each cover only their own hop: Ethernet has a CRC per frame, TCP a weak 16-bit checksum per segment, disks have internal error correction, and file systems like ZFS verify block checksums on read. All of them miss corruption that happens before data reaches them, such as a bad RAM module in your upload service. Only application-level checksums cover the whole path, so rely on them for the final guarantee. Also protect storage (verify on read, scrub, repair), network (verify on receipt, retransmit) and replication (verify when copying, compare replicas periodically).
Repair. Replace a bad copy from a healthy replica, or rebuild it with erasure coding: split data into k data pieces plus m parity pieces so any k of the k+m pieces can rebuild the original, using less space than 3 full copies.
Merkle trees. A Merkle tree (hash tree) has a hash of one data block at each leaf, and every internal node is the hash of its children. The root hash summarises the entire dataset.
Root = H(H12 + H34)
/ \
H12 = H(H1 + H2) H34 = H(H3 + H4)
/ \ / \
H1 H2 H3 H4
Block1 Block2 Block3 Block4
To compare two replicas: exchange root hashes. If equal, the data is identical, done. If not, compare children and descend only into subtrees that differ (here H34 differs, then H3), until you reach the differing blocks and sync just those. With N blocks this takes about log N comparisons instead of N. Changing any leaf changes the root, which also gives tamper evidence. Scrubbing uses I/O that competes with user traffic, so systems throttle it.
A simple example
End-to-end integrity is sealing a package at the factory and checking the seal at your door. A Merkle tree is comparing two library catalogues: whole-library summary first, then each floor, then each shelf, only where summaries disagree.
System design example
A Dynamo-style database keeps three replicas of each key range, each with a Merkle tree. Periodically replicas exchange root hashes and, where they differ, walk down and copy only the differing blocks. Clients also send a checksum with every upload, verified on receipt and on every read, and a throttled background scrubber repairs cold data from replicas.
Summary
- Checksums detect corruption; replicas or erasure coding repair it.
- Compute checksums at the source and verify at the destination.
- Merkle trees compare large datasets with about log N hash comparisons.
Architecture Diagram
Checksum at the source, verify at the sink, and compare replicas with Merkle trees.
- 1The producer computes a checksum and sends it with the data.
- 2The destination verifies before accepting.
- 3Replicas compare Merkle tree hashes and repair only differing blocks.
Common Interview Questions
Chapter quiz
Checksums · 5 questions
1.What is silent data corruption?
2.Why is CRC unsuitable against attackers?
3.Which hash is widely considered safe today against tampering?
4.What does a checksum do?
5.What is the root of a Merkle tree?
0 of 5 answered
Finished this lesson?
0 of 91 lessons done · 0% of the course

