Abstract
Internet-scale distributed systems often replicate data at multiple geographic locations to provide low latency and high availability. The Conflict-free Replicated Data Type (CRDT) is a framework that provides a principled approach to maintaining eventual consistency among data replicas. CRDTs have been notoriously difficult to design and implement correctly. Subtle deep bugs lie in the complex and tedious handling of all possible cases of conflicting data updates. We argue that the CRDT design should be formally specified and model-checked to uncover deep bugs. The implementation further needs to be systematically tested. On the one hand, the testing needs to inherit the exhaustive nature of the model checking and ensures the coverage of testing. On the other hand, the testing is expected to find coding errors which cannot be detected by design level verification. Towards the challenges above, we propose the Model Checking-driven Explorative Testing (MET) framework. At the design level, MET uses TLA+ to specify and model check CRDT designs. At the implementation level, MET conducts model checking-driven explorative testing, in the sense that the test cases are automatically generated from the model checking traces. The system execution is controlled to proceed deterministically, following the model checking trace. The explorative testing systematically controls and permutes all nondeterministic message reorderings. We apply MET in our practical development of CRDTs. The bugs in both designs and implementations of CRDTs are found. As for bugs which can be found by traditional testing techniques, MET greatly reduces the cost of fixing the bugs. Moreover, MET can find subtle deep bugs which cannot be found by existing techniques at a reasonable cost. We further discuss how MET provides us with sufficient confidence in the correctness of our CRDT designs and implementations.
Introduction
In distributed computing, the CAP theorem necessitates trade-offs between consistency, availability, and partition tolerance. Conflict-free Replicated Data Types (CRDTs) offer a path to high availability and low latency by allowing replicas to diverge and eventually converge without expensive consensus protocols. However, ensuring the correctness of CRDTs is a significant challenge. Developers often encounter "deep bugs"—errors that only surface under rare, specific interleavings of concurrent updates and network messages.
Traditional stress testing is often insufficient for these systems because the state space is exponentially large, making it unlikely to hit specific problematic interleavings. Conversely, formal verification methods like model checking typically validate the design but do not account for implementation errors, such as transcription bugs (coding errors) or assumption errors (mismatches between protocol requirements and the underlying platform's behavior).
The MET Framework
To bridge this gap, we introduce MET (Model Checking-Driven Explorative Testing). MET integrates formal design verification with systematic implementation testing through a two-layered approach.
Design Layer: Model Checking
At the design level, developers specify the CRDT protocol using TLA+. To manage the "state explosion problem," MET employs "coarsening." This technique groups atomic actions—such as receiving, processing, and sending a message—into single steps. This allows the model checker to focus on the core conflict-resolution logic rather than granular network events.
Code Layer: Explorative Testing
The core innovation of MET is its ability to translate model-checked traces into deterministic test cases for the actual implementation. This layer relies on three pillars:
- Controllability: The networking layer of the implementation (e.g., a Redis-based CRDT store) is modified to allow a central Test Manager to intercept and release messages in the exact order specified by the model.
- Observability: Custom APIs are added to the implementation, enabling the Test Manager to inspect the internal state of replicas.
- The Oracle: The sequence of states predicted by the TLA+ model serves as the ground truth. Any deviation in the implementation's state from the model's prediction signals a bug.
Evaluation and Results
We evaluated MET on two complex CRDTs: Rwf-RPQ (a Replicated Priority Queue with a remove-win strategy) and Rwf-List (a Replicated List for collaborative editing). The framework analyzed millions of execution traces generated by the TLA+ model checker.
MET successfully identified 7 distinct bugs in our CRDT implementations. Notably, it found bugs that traditional stress testing missed. For instance, one design bug was discovered significantly faster with MET than with random testing, providing a minimal, reproducible trace that simplified debugging. Another "assumption bug" was found that required a specific sequence of network delays and concurrent operations—a scenario nearly impossible to hit through random testing.
For the Rwf-List CRDT (3 servers, 3 requests), MET checked over 5 million traces in approximately 51 seconds of model checking time, followed by 1.5 hours of automated testing.
Key Insights
- Small Scope Hypothesis: Most distributed system bugs can be triggered by a small number of nodes and events. MET leverages this by exhaustively checking critical interleavings within a limited scope (e.g., 3 replicas).
- Deterministic Replay: By forcing the implementation to follow model-checked traces, MET converts non-deterministic distributed failures into reproducible unit tests.
- Bug Categorization: MET helps distinguish between transcription bugs (coding errors) and assumption bugs (protocol/platform mismatches, such as assuming causal delivery when it isn't provided).
Conclusion and Future Work
While MET provides high confidence in CRDT correctness, it is currently semi-automatic, requiring manual TLA+ specification and state-inspection API implementation. Furthermore, state explosion remains a challenge as the number of requests increases. Future work will focus on applying MET to broader distributed components and exploring heuristic exploration strategies to prioritize the most "suspicious" execution traces.
Summary updated