CRDT

Also known as: Conflict-free replicated data type

On this page 7

A CRDT (conflict-free replicated data type) is a data structure designed so that independent replicas can accept updates without coordination and still converge to the same state once they have exchanged their updates. In database replication, CRDTs offer a mathematically grounded alternative to locking, consensus and last-writer-wins rules for systems that must stay writable during network partitions.

The guarantee CRDTs provide is called strong eventual consistency: any two replicas that have received the same set of updates are in the same state, regardless of the order in which those updates arrived. This property makes CRDTs a natural fit for multi-primary replication, geo-replication across regions and offline-first applications that synchronize later.

How CRDTs guarantee convergence

A CRDT converges because its merge operation is designed to be commutative, associative and idempotent. Commutativity means the order of merges does not matter, associativity means grouping does not matter, and idempotence means receiving the same update twice has no additional effect. Together these properties remove the need for a coordinator that decides the order of writes.

Formally, the possible states of a state-based CRDT form a join-semilattice, a partially ordered set in which any two states have a least upper bound. Every local update moves the state upward in that order, and merging two replicas simply computes their least upper bound. Because the bound is unique, all replicas that have seen the same information end up at exactly the same point.

The algebraic properties of the merge are summarized in the table below, together with what each one means in practice for a replicated database.

PropertyMeaningPractical consequence
Commutativitymerge(a, b) equals merge(b, a)Updates may arrive in any order
AssociativityGrouping of merges is irrelevantReplicas can gossip through any topology
Idempotencemerge(a, a) equals aDuplicate delivery is harmless
MonotonicityState only grows in the lattice orderNo update is silently lost by a merge
Algebraic properties behind CRDT merges

State-based and operation-based CRDTs

CRDTs come in two main families that differ in what replicas send to each other. State-based CRDTs, also called convergent replicated data types (CvRDTs), ship the full state and merge it with the join function. Operation-based CRDTs, or commutative replicated data types (CmRDTs), broadcast individual operations that must commute when applied concurrently.

A third variant, the delta-state CRDT, sends only the recently changed fragment of the state. It keeps the simple delivery assumptions of state-based designs while reducing bandwidth to a level close to operation-based designs, which is why many modern implementations adopt it.

FamilyWhat is transmittedDelivery requirementTypical cost
State-based (CvRDT)Entire replica stateAny order, duplicates allowedHigh bandwidth for large states
Operation-based (CmRDT)Individual operationsExactly-once, often causal orderLow bandwidth, stricter messaging
Delta-state CRDTChanged state fragmentsAny order, duplicates allowedLow bandwidth, moderate complexity
Comparison of CRDT families

Operation-based designs depend on a reliable causal broadcast layer, so the complexity moves from the data type into the messaging system. State-based designs tolerate lossy, unordered networks but can become expensive when the state holds millions of elements.

Common CRDT types and their semantics

Practical CRDT libraries offer a catalog of building blocks such as counters, registers, sets, maps and sequences. Each type encodes a specific policy for concurrent updates, and choosing the type is effectively choosing the conflict resolution semantics of the application.

TypeHow it worksConcurrent update behavior
G-CounterOne increment-only slot per replica, value is the sumAll increments are preserved
PN-CounterPair of G-Counters for increments and decrementsNet value reflects every operation
LWW-RegisterValue tagged with a timestampHighest timestamp wins, others are discarded
MV-RegisterKeeps all concurrent valuesApplication resolves siblings later
OR-SetAdds carry unique tags, removes target observed tagsAdd wins over a concurrent remove
Sequence CRDT (RGA, Logoot)Elements carry globally unique positionsConcurrent text inserts are interleaved deterministically
Widely used CRDT types

The observed-remove set illustrates the design style well. A remove only deletes the add tags that the removing replica has actually seen, so a concurrent add with a fresh tag survives. The result is add-wins semantics, which suits shopping carts and membership lists but may surprise users who expect a delete to be final.

CRDTs compared with other replication strategies

CRDTs occupy a distinct place among replication strategies because they trade strong consistency for availability without discarding concurrent writes. Consensus protocols such as Raft and Paxos achieve a single agreed order but require a quorum, so a minority partition cannot accept writes.

ApproachWrite availability during partitionConsistency modelConflict handling
CRDTEvery replica stays writableStrong eventual consistencyResolved by data type design
Raft or Paxos consensusOnly the majority sideLinearizableConflicts prevented by ordering
Last-writer-wins replicationEvery replica stays writableEventual consistencyOlder concurrent writes lost
Synchronous primary-replicaPrimary side onlyStrongSingle writer avoids conflicts
How CRDTs relate to neighboring approaches

In practice, the CRDT model removes the split-brain risk for data integrity, because divergent replicas are expected and always reconcilable. It does not remove the need to reason about business invariants: a CRDT cannot enforce that a bank balance never drops below zero across replicas without some form of coordination.

Limitations and engineering pitfalls

CRDTs solve convergence but introduce costs that experienced teams plan for early. The most frequent problems concern metadata growth, garbage collection and semantics that differ from what users expect.

  • Tombstones and metadata overhead: removed elements often leave markers, and version vectors grow with the number of replicas, so storage can exceed the payload size.
  • Garbage collection needs coordination: safely purging tombstones requires knowing that every replica has seen the removal, which reintroduces a form of agreement.
  • No global invariants: uniqueness constraints, foreign keys and non-negative balances cannot be guaranteed by convergence alone.
  • Clock dependence in LWW types: last-writer-wins registers rely on timestamps, and clock skew can make an older write win.
  • Surprising merge results: interleaved text edits or resurrected set items are correct by definition but may look wrong to end users.

A sound design therefore combines CRDTs for high-availability data paths with coordinated transactions for the small set of operations that require strict invariants, such as payments or inventory reservations.

The idea in brief

A CRDT is a way of storing data so that several copies can be changed at the same time, in different places, and still end up identical later. Each copy keeps working even when the network between them is down.

Think of several people adding tally marks to their own copy of a scoreboard. When the copies meet, everyone simply combines the marks, and the total is always the same no matter who met whom first. The rules for combining are built into the data itself, so no referee is needed.

A practical scenario

A retail company runs its shopping cart service in three regions, each with its own database replica. A customer adds a jacket on a phone connected to the European region while, a moment later, a laptop connected to the American region removes an older item from the same cart. A brief network partition separates the two regions for about 20 seconds.

The cart is stored as an observed-remove set, and the item quantities are PN-Counters. Both regions accept the writes locally with no added latency. When the link returns, the replicas exchange delta states and merge them. The removal affects only the item the laptop had seen, and the newly added jacket survives because its add tag was unknown to the remover.

The outcome is that both changes are preserved and all three regions show the same cart within a second of reconnection. Checkout, however, still goes through a coordinated transaction against inventory, because stock levels must never fall below zero.