The interview problem

Practice prompt

Two replicas each hold a terabyte of key-value data. Detect and repair small divergent ranges without transferring the entire dataset, while concurrent writes continue.

Original practice, not a reported company interview. All scenarios and worked numbers are illustrative. Interview date: not applicable. Sources retrieved September 30, 2026.

1. Scope and assumptions

Assume deterministic serialization, collision-resistant hashes and versioned records with a documented conflict resolver. Hash agreement is evidence under those assumptions, not a proof that the business values are correct.

2. Worked approach

comparable snapshots
  → root comparison
  → mismatched leaves
  → version-aware record repair

Take comparable logical snapshots or label each tree with its snapshot frontier. Partition the same ordered key space into deterministic leaves. Hash canonical key/version/value records, then combine child hashes into a tree. Compare roots and recursively exchange children only for mismatched ranges.

At mismatched leaves, exchange records and tombstones with versions, apply the resolver and write conditionally against current versions. A repair from an older snapshot must not overwrite a newer write. Schedule repeated rounds to catch changes after the snapshot; rate-limit repair separately from foreground traffic and track the oldest unrepaired range.

3. Calculate the example

For 1,024 equally sized leaves, a binary tree has 10 levels from root to leaf. With exactly one differing leaf and cached roots, exchanging both child hashes at each level uses about 20 hash values, or 640 bytes at 32 bytes/hash, before metadata and actual record transfer. If all leaves differ, the traversal approaches the full tree and saves little. A one-terabyte dataset with 1,024 equal-byte leaves still needs roughly one gigabyte of leaf data examined for a single mismatch unless finer indexing is available.

4. Failure cases and trade-offs

Different canonical encodings produce disagreements without logical divergence. Different snapshots can produce repeated mismatches. Prematurely deleting tombstones lets an old replica resurrect removed keys. Offline replicas need a defined maximum repair gap or a full rebuild path.

Finer leaves reduce record exchange but increase tree memory and maintenance. Incremental trees reduce scan cost but make update correctness harder. Hash trees locate disagreement; they do not choose the winning version or replace consensus when strong agreement is required.

5. Validate the result

Inject a stale value, a delete, a concurrent write and a serialization mismatch. Verify convergence without overwriting newer versions and measure repair bandwidth under one-leaf and all-leaf divergence.

6. Interview follow-ups and self-review

How are new key ranges represented? What happens after tombstone retention expires?

Reward comparable snapshots, deterministic ranges, version-aware repair and a cost estimate that separates hashes from data.

Sources and related practice

Technical reference: cassandra.apache.org — Replica repair background; specific tree protocol and numerical analysis are original.

Exact publication/update date not established in this review. Retrieved September 30, 2026. This reference supports the named technical concept; the proposed workflow and examples are original, not a documented vendor implementation or interview report.

Continue with Capture a consistent distributed snapshot; Compact an event log without resurrecting deleted keys.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.