CRDT
Conflict-free Replicated Data Type: a data structure that can be updated independently on different nodes and merged automatically without conflicts. Powers real-time collaboration like Google Docs.
What is CRDT?
In short
A CRDT (Conflict-free Replicated Data Type) is a data structure that multiple machines can update at the same time without coordinating, and whose copies always converge to the same final state when they exchange changes. The merge rules are baked into the data type itself, so concurrent edits never produce a conflict and no central server has to decide a winner.
What a CRDT actually is
Picture two people editing the same shopping list while one of them is offline on a train. With a normal database you would have to lock the list or pick one person's version and throw the other's away. A CRDT lets both keep editing their own copy, and when the train reconnects, the two copies merge into one list that contains everyone's changes. Nobody had to ask a server who wins.
The trick is that a CRDT is designed so that its merge operation is commutative, associative, and idempotent. In plain terms: it does not matter what order the changes arrive in, it does not matter how they are grouped, and applying the same change twice does no harm. Because those three properties hold, any two replicas that have seen the same set of updates end up byte-for-byte identical. This guarantee is called strong eventual consistency.
CRDTs come in two flavors. State-based (CvRDT) replicas ship their whole current state and merge it with a join function. Operation-based (CmRDT) replicas ship just the individual operations and replay them. State-based is simpler and tolerant of dropped or duplicated messages; operation-based sends far less data but needs a delivery layer that does not lose messages.
How the merge works under the hood
The simplest CRDT is a grow-only counter (G-Counter). Each replica keeps its own slot in a map and only ever increments its own slot. To read the total you sum every slot. To merge two replicas you take the max of each slot. Two nodes can increment at the same time and the sums still add up correctly because each only touches its own number.
Sets are harder because deletion is the enemy of merging. A grow-only set (G-Set) only allows adds. A two-phase set (2P-Set) keeps an add set and a tombstone set, so a removed item can never come back. The widely used OR-Set (Observed-Remove Set) tags every add with a unique id, so concurrent add and remove resolve cleanly: you only remove the exact adds you actually saw, and a fresh add survives.
Collaborative text, the famous Google Docs case, uses sequence CRDTs like RGA or the tree structure behind Yjs and Automerge. Each character gets a unique, densely ordered identifier so two people typing in the same spot interleave deterministically instead of overwriting each other. Causality is tracked with version vectors so every replica knows which updates it has already seen and can ignore duplicates.
When to reach for one, and the cost
CRDTs shine when you need offline-first or multi-leader writes with no central coordinator: collaborative editors, mobile apps that sync when they get signal, multiplayer cursors, shopping carts in a multi-region store. They let every node accept writes immediately, which means low latency and high availability even during a network partition. On the CAP spectrum they pick availability and partition tolerance.
The price is metadata and semantics. Tombstones and unique tags mean the structure can grow larger than the data it holds, and old CRDT designs that never garbage-collected tombstones would bloat forever. Modern libraries compact this, but you still pay more bytes than a plain value would cost.
The deeper trade-off is that automatic merging is not the same as correct business logic. A CRDT guarantees the copies converge, not that the converged result is what a human wanted. Amazon's classic shopping-cart example merges concurrent edits by union, which is why a deleted item could reappear in your cart. If your invariant is something like account balance must never go below zero, a CRDT cannot enforce that across partitions, and you need consensus instead.
A concrete example: Redis and the shopping cart
Redis Enterprise ships active-active databases built directly on CRDTs (they call them CRDBs). You can run the same database in data centers in Mumbai, Frankfurt, and Virginia, let users write to whichever is closest, and Redis merges the replicas in the background. A counter incremented in two regions at once sums correctly; a string uses last-write-wins keyed by a hybrid clock; a set uses OR-Set semantics.
Concretely, suppose a user in India adds a phone to their cart while a flaky connection causes a retry that also lands in the EU region. Because the cart is an OR-Set, the duplicate add is deduplicated by its tag and the item appears once, not twice. If they remove the phone in one region while a recommendation service adds an accessory in another, both operations survive the merge and no write is silently lost.
This is the same pattern behind Riak's data types, Microsoft's Azure Cosmos DB multi-region writes, and figma-style design tools. The application gets fast local writes everywhere and a single converged truth a few hundred milliseconds later, without ever standing up a leader election or a global lock.
Where it is used in production
Redis Enterprise Active-Active
Multi-region databases (CRDBs) use CRDT counters, registers, and sets so writes in any region merge automatically.
Figma
Its multiplayer engine uses CRDT-style structures so many designers can edit the same canvas live without locking objects.
Riak
Ships built-in CRDT data types (counters, sets, maps, flags) for highly available multi-master key-value storage.
Apple Notes
Uses CRDT-based syncing so edits made offline on an iPhone merge cleanly with edits on a Mac when both come back online.
Frequently asked questions
- What is the difference between a CRDT and operational transformation (OT)?
- OT, used in older Google Docs, transforms each operation against concurrent ones and usually relies on a central server to order them. A CRDT bakes conflict resolution into the data structure itself, so it works peer-to-peer with no central coordinator and no transformation step. CRDTs are easier to reason about offline but often carry more metadata.
- Do CRDTs guarantee my data is correct after a merge?
- They guarantee convergence, meaning every replica ends up identical, not that the result matches your business rules. A union-based set will happily resurrect a deleted item, and no CRDT can enforce an invariant like balance must stay above zero across a partition. For hard invariants you still need consensus or a single writer.
- What is the difference between state-based and operation-based CRDTs?
- State-based (CvRDT) replicas send their entire current state and merge with a join function, which tolerates lost or duplicated messages but sends more data. Operation-based (CmRDT) replicas send only the individual operations, which is far smaller but requires a network layer that delivers each operation exactly once and in causal order.
- Why do CRDTs use so much extra metadata?
- To merge safely they track causality and identity. Sets tag each add with a unique id and keep tombstones for removals, and many types carry version vectors per replica. This metadata can outgrow the actual data, though modern libraries like Yjs and Automerge compact and garbage-collect it aggressively.
- When should I not use a CRDT?
- Skip them when you need strong consistency or global uniqueness, such as enforcing a non-negative balance, allocating a unique seat, or any rule that must hold the instant a write happens. Those need consensus protocols like Raft or Paxos. CRDTs are the right tool for collaborative, offline-first, multi-region workloads where availability matters more than instant global agreement.
Learn CRDT hands-on
This page explains the idea. The full lesson lets you step through the ring as servers join and leave, read the implementation, and check yourself with a quiz. It is one of 760+ lessons in the System Design Masterclass, from your first API call to distributed consensus. Eleven Foundation lessons are free, no signup. Lifetime access is ₹499 in India or $7.99 worldwide, one payment, no subscription.
Related lessons
Lessons that touch on CRDT as part of a larger topic.
See also
Related glossary terms you might want to look up next.
Eventual Consistency
A consistency model where updates propagate asynchronously and all replicas will eventually converge to the same value. Trades immediacy for availability.
Multi-Leader Replication
A replication topology where multiple nodes accept writes independently and sync with each other. Useful for multi-datacenter setups but creates conflict resolution challenges.
Vector Clock
A logical clock that tracks causality across distributed nodes using a vector of counters. Each node increments its own counter and merges vectors on message receipt.
CAP Theorem
In a distributed system, you can only guarantee two of three: Consistency, Availability, and Partition tolerance. You must choose your trade-off.
Consensus
The process of getting multiple nodes in a distributed system to agree on a single value. The foundation of distributed databases and coordination services.
Paxos
A family of protocols for solving consensus in unreliable networks. Famously difficult to understand but mathematically proven correct.