CRDT Explained: How Shared Data Stays in Sync Without Locks

CRDT explained in plain terms means understanding a kind of data structure that lets several copies of the same document, list, or counter agree with each other, even when they are edited at the same time in different places. The central question is how two people can edit the same shared file offline and still end up with one correct version, and the answer is a data type designed so that any two copies can always be merged safely.

A CRDT, short for conflict-free replicated data type, is a data structure whose replicas can be updated independently and then merged in any order, always arriving at the same result. Unlike a conventional database, it needs no central server to decide which change wins, and no locks to stop people editing at the same time.

The idea is simple: build the merge rule into the data itself. Each replica keeps enough extra information, such as a unique tag on every edit, that merging two versions is a matter of combining their contents according to fixed rules, rather than guessing which change should win. This article explains what a CRDT is, how it works, and where it is used.

Key takeaways

  • A CRDT lets replicas be edited independently and merged in any order.
  • Merging is built into the data type, so no central server decides.
  • State-based CRDTs merge whole states; operation-based ones send edits.
  • They guarantee eventual consistency without locks or coordination.
  • They power collaborative editing, offline apps, and distributed stores.

What a CRDT is

A CRDT is a data structure with a merge operation that is commutative, associative, and idempotent, which are the mathematical properties that make merging safe. Commutative means the order of merges does not matter, associative means grouping does not matter, and idempotent means merging the same change twice has no extra effect, so replicas converge to the same state no matter how updates travel between them.

There are two broad families. A state-based CRDT, also called a convergent replicated data type, sends its whole state to other replicas, which merge it with their own. An operation-based CRDT, also called a commutative replicated data type, sends only the individual operations, such as insert or delete, and each replica applies them in whatever order they arrive.

CRDTs were developed to solve a problem that traditional databases handle badly: collaboration without a connection. A document edited on a train, a list updated on a phone with no signal, or a counter changed in two data centres at once all need a way to reconcile, and a CRDT provides it without asking a server to arbitrate. Our guide to distributed systems explains the setting in which replicas must agree, and our guide to the CAP theorem explains the trade-off between availability and consistency that CRDTs resolve in favour of availability.

How a CRDT works

Take a simple example: a counter that can only grow. Each replica holds a number, and when it is incremented, the new value is shared. Merging two counters means taking the larger of the two values, which is safe in any order, and the result is the total number of increments across all replicas, with none lost and none counted twice.

A set is only slightly harder. A grow-only set merges by taking the union of its members, which is again safe in any order. Supporting removal needs extra care, because a replica that has not yet seen an addition could reintroduce a deleted item when it merges, so practical designs keep a tombstone, a small record that an item was removed, and the merge rule respects it.

Text editing is the hardest common case, and it is where CRDTs shine. Each character, or each block of text, carries a unique identifier and a position relative to its neighbours, so when two people type at the same place, both insertions survive, ordered by their identifiers, and no text is silently lost. The document that results is the same on every replica, even though the edits arrived in different orders.

Operation-based CRDTs add a delivery requirement: every operation must reach every replica exactly once, in an order that respects causality, which usually means a reliable broadcast layer underneath. State-based CRDTs avoid that requirement, since merging a whole state is safe even if some messages are lost or duplicated, but they send more data with each sync.

Underneath both families is the same insight: if the merge rule is designed correctly, convergence is guaranteed by the mathematics, not by timing, luck, or a coordinator. A system built on CRDTs can therefore keep working through network partitions, with replicas diverging while apart and converging again when they reconnect.

A dark desk with two laptops showing the same glowing green document, their screens linked by lines of light
A dark desk with two laptops showing the same glowing green document, their screens linked by lines of light, shows how a CRDT works: two copies edited apart, merging back into one.

Comparing a CRDT with other approaches

A CRDT is one of several ways to keep shared data consistent, and each was built with a different emphasis. Operational transformation rewrites edits so they apply cleanly, last-writer-wins keeps only the newest change, and a central database avoids the problem by making one copy the truth, but each approach has its own costs.

The table below sets out the main contrasts between the leading approaches.

Aspect CRDT Operational transformation Last-writer-wins
Merge rule Built into the data type Transforms each operation Newest timestamp wins
Needs a server No Usually yes Yes, for the clock
Offline editing Full support Limited Possible, with loss
Data loss risk Very low Low if implemented well Losing edits are common
Best for Peer-to-peer collaboration Centralised editors Simple caches and settings

The practical result is that a CRDT is the right choice when replicas must work offline and merge without a server, operational transformation suits centralised editors with a server in the loop, and last-writer-wins is enough only where losing an occasional edit does not matter.

Where a CRDT is used

Collaborative editing is the best-known use. Modern document tools that let several people type at once, with changes appearing on every screen in real time, often use CRDTs under the surface, so that two people editing the same paragraph never overwrite each other, even when their edits cross on the network.

Offline-first applications use CRDTs to keep working without a connection. A note-taking app, a to-do list, or a field data tool can accept edits while offline, store them locally, and merge them with the shared copy when the connection returns, without asking the user to resolve a conflict.

Distributed databases use CRDTs for data that must stay available in several places at once. A shopping cart, a user profile, or a counter can be replicated across data centres, updated in any of them, and merged when the replicas sync, giving the system high availability without a single point of coordination.

Peer-to-peer systems use CRDTs because there is no server at all. When devices sync directly with each other, perhaps over a local network or a mesh, a CRDT gives them a way to agree on shared state using only the messages they exchange, with no authority to appeal to.

Version control and synchronisation tools use CRDT-like ideas for merging. While a system such as Git asks a human to resolve conflicting changes, a CRDT-based tool can merge automatically in far more cases, because the data structure itself knows how to combine two versions safely.

Strengths and limits

The greatest strength of a CRDT is that convergence is guaranteed by design. Once the merge rule is correct, replicas cannot diverge permanently, and no amount of delay, duplication, or reordering of messages can produce a different result, which makes the system far easier to reason about than one built on ad-hoc conflict handling.

It is also a strength that CRDTs need no coordination. Replicas can accept writes at any time, even while disconnected, so the system stays available during network partitions, and there is no leader to elect, no lock to wait for, and no single point of failure.

The limits are real, though. The extra metadata that makes merging safe also makes CRDTs heavier than plain data: tombstones accumulate, identifiers grow, and a long-lived document can carry a large amount of history. Some data types are also hard to express as CRDTs, and a merge that preserves every edit is not always what a user wants, since a deleted paragraph that reappears because of a late merge can be surprising.

CRDT checklist

  • Choose a CRDT only when replicas must merge without a server.
  • Pick state-based merging if messages may be lost or duplicated.
  • Pick operation-based merging if bandwidth matters most.
  • Keep tombstones, and compact them when it is safe to do so.
  • Test merging with edits arriving in every possible order.
  • Test long offline periods followed by a sudden reconnect.
  • Make sure identifiers are unique across all replicas.
  • Decide how deletions should behave before you build.
  • Measure the metadata overhead on large, long-lived documents.

Frequently asked questions

What is a CRDT in simple terms?

It is a data structure designed so that copies of it can be changed independently and then merged, always arriving at the same result. The merge rule is built into the data itself, so no server needs to decide which change wins.

What is the difference between a state-based and an operation-based CRDT?

A state-based CRDT sends its whole state to other replicas, which merge it with their own, and it tolerates lost or duplicated messages. An operation-based CRDT sends only the individual edits, which is more efficient, but every operation must reach every replica exactly once.

Do CRDTs need a central server?

No, and that is one of their main advantages. Replicas can sync directly with each other, which is why CRDTs are used in peer-to-peer systems and in apps that must keep working while offline.

Can a CRDT lose data?

A correctly implemented CRDT preserves every edit, including concurrent ones, which is why it is safer than last-writer-wins. Data can still be lost if the application deletes it deliberately, or if a bug in the merge rule drops an update.

What is a tombstone in a CRDT?

It is a small record that an item was deleted, kept so that a replica which has not yet seen the deletion does not reintroduce the item when it merges. Tombstones can be removed once every replica is known to have seen the deletion.

When should I not use a CRDT?

When a single database can hold the data, when strong consistency is required, or when the data type does not fit the CRDT model well. A CRDT is a tool for availability and offline work, not a replacement for every database.

The bottom line

CRDT explained in one line is this: design the data so that merging is always safe, and replicas can agree without ever asking permission.

It is the data structure behind offline editing and peer-to-peer collaboration, trading some extra metadata for the freedom to work anywhere and sync whenever.

This article is general information about how CRDTs work, not advice about choosing a replication design for a particular system.

Latest articles

Scroll to Top