Keep CALM and CRDT On

Shadaj Laddad, Conor Power, Mae Milano, Alvin Cheung, Natacha Crooks, Joseph M. Hellerstein

Abstract

Conflict-Free Replicated Data Types (CRDTs) have emerged as a powerful tool for building distributed systems that guarantee eventual convergence without the latency of heavy coordination. However, a critical gap exists between the convergence of data state and the consistency of the queries performed against that state. This paper identifies the phenomenon of "Schrödinger consistency"—where data is consistent only until it is observed—and proposes a formal framework based on the CALM Theorem to resolve it. By transitioning from CRDT libraries to managed CRDT data stores, the authors advocate for a system-level approach to distributed consistency that automates the distinction between safe, coordination-free queries and those requiring global synchronization.

Introduction

In the design of distributed systems, developers are often forced to choose between the "strong consistency" of protocols like Paxos or Raft—which are robust but slow—and the "eventual consistency" of high-availability systems, which are fast but prone to data anomalies. CRDTs (Conflict-Free Replicated Data Types) were designed to bridge this gap. By using mathematical structures like sets or counters that follow specific merge rules, CRDTs ensure that different replicas will eventually reach the same state regardless of the order in which operations are received.

However, the authors of "Keep CALM and CRDT On" argue that the community has succumbed to a "dangerous misread" of CRDT safety. While the internal state of a CRDT is guaranteed to converge, the observations (reads and queries) made of that state remain unconstrained. This leads to a situation where a developer might read a value that is mathematically valid at a local replica but logically incorrect in the context of the global system state.

The Problem: Schrödinger Consistency

The authors wittily describe the current state of CRDT usage as "Schrödinger consistency": the data is guaranteed to be consistent only as long as it is not viewed. The moment a query is executed, the standard safety guarantees of the CRDT vanish.

Consider a "Two-Phase Set" used for a shopping cart. If a user adds an item (e.g., a Ferrari) and then immediately removes it, different replicas may receive these operations at different times. If a "checkout" query runs on a replica that has processed the "add" but not yet the "remove," the system might charge the user for an item they already deleted. This "early read" bug occurs because the query is sensitive to the intermediate, non-converged state of the replica. Currently, the burden of identifying these risks falls entirely on the developer, who must manually reason about whether a specific read requires a global lock or can be performed locally.

Methodology: Applying the CALM Theorem

To address this, the authors propose applying the CALM Theorem (Consistency As Logical Monotonicity) to CRDT queries. The CALM Theorem provides a formal gauge for safety: distributed programs can reach consistency without coordination if and only if they are monotonic.

Query Classification

The paper categorizes CRDT observations into two distinct buckets:

  1. Monotone Queries: These are queries where "more input only leads to more output." For example, asking "Is the count greater than 50?" is monotonic. Once the count crosses that threshold, additional data will not make the statement false. These queries are safe to run locally on any replica without coordination.
  2. Non-Monotone Queries: These are queries that depend on the absence of information, such as "What are the current items in the set?" or "Is the set empty?" Because a pending "remove" operation could change the result, these queries require coordination (such as a quorum read) to ensure a consistent view.

The Architectural Shift: From Libraries to Data Stores

The authors argue that the current practice of using CRDTs as simple objects in a programming library is insufficient. Instead, they propose a shift toward managed CRDT Data Stores.

By moving CRDT management into a dedicated store with a SQL-like interface, the system can provide several key advantages:

  • Automatic Optimization: A data store can automatically detect if a query is monotonic and decide whether to execute it locally or require coordination.
  • Relational Algebra for Lattices: SQL is naturally suited for this model because many of its operators (SELECT, PROJECT, JOIN, UNION) are monotonic. Only specific operators, like set difference (EXCEPT) or NOT EXISTS, break monotonicity and signal the need for coordination.
  • Physical Management: A managed store can handle complex "physical" tasks like garbage collection (pruning old operation logs) and "delta-gossip" (efficiently synchronizing only the changes rather than the entire state) without developer intervention.

Key Insights and Future Directions

Beyond the formal classification of queries, the paper introduces the "Apology" strategy for high-performance scenarios. If a non-monotone query is too slow to run with coordination, the system could return a "stale" result immediately. By using lineage tracing, the system can then identify if that result was incorrect once the data converges and automatically issue an "apology" or a compensating action.

While the paper is a vision piece, it provides a rigorous roadmap for the next generation of distributed databases. The authors are currently working on formalizing relational algebra for semi-lattices and building prototypes that use program synthesis to automate the most difficult aspects of CRDT maintenance. The goal is a future where the database engine itself understands the mathematical properties of the data, allowing developers to "Keep CALM" while the system handles the complexities of consistency.

Summary updated

BibTeX
@article{laddad2022keep,
  author = {Shadaj Laddad and Conor Power and Mae Milano and Alvin Cheung and Natacha Crooks and Joseph M. Hellerstein},
  title = {{Keep CALM and CRDT On}},
  journal = {Proc. VLDB Endow.},
  year = {2022},
  doi = {10.14778/3574245.3574268},
}
Figure