A collaborative editing platform receives a report that one document occasionally shows different content to different users, but it cannot be reproduced. How do you investigate a rare, non-deterministic, distributed bug?
Show the full answer Hide the answer
Why the usual approach fails
Reproduction is the normal first step and it is unavailable here: the bug depends on timing, on a specific interleaving of concurrent operations, and on network conditions you cannot recreate. Adding logging and waiting is slow, and the volume needed to catch a rare event is prohibitive.
The investigation
1. Capture the state when it happens, not when you notice. Add a client-side integrity check — a checksum of the document state — reported periodically with the client's operation sequence position. When two clients report different checksums for the same version, the system has detected the divergence itself rather than waiting for a user report.
This is the highest-value change and it converts an unreproducible bug into a detected one with data attached.
2. Retain the operation log around detections. The sequence of operations, their logical timestamps, their origin clients and the order each client applied them. Divergence is almost always an ordering or merge problem, and the operation log is the only artefact that shows it.
3. Look for the classic causes, in order of likelihood: - A non-commutative operation pair applied in different orders on different clients. In a conflict-free design this should be impossible; where it happens, an operation type usually violates the commutativity assumption. - A tie-break that is not deterministic across replicas — for example one using wall-clock time, which differs between machines, rather than a logical clock with a stable client-id tiebreaker. - A missed operation after reconnection, where the replay buffer boundary was handled incorrectly. - Client version skew, where two clients running different releases interpret an operation differently. This is a very common cause and is easy to check first.
4. Replay deterministically. With the operation log captured, replay it offline in a harness. If the divergence reproduces, you have a fast, deterministic test. This is the payoff for step 2 and is what turns the investigation from observation into engineering.
5. Bisect by client version and by operation type across all detected divergences, looking for concentration. Rare bugs that seem random are usually concentrated once you have enough instances.
The systemic change
Make divergence detectable by design. Periodic state checksums, version vectors compared across clients, and an automatic report when they disagree. Then this class of bug is discovered by the system in minutes rather than by a user weeks later, and every occurrence arrives with the evidence needed to diagnose it.
For any system with replicated mutable state, the ability to detect that replicas disagree is a first-class architectural requirement, not a debugging convenience — because without it, silent divergence is indistinguishable from correct operation.