What a CRDT assumes, and what it will not give you
A CRDT is a data type whose merge function is commutative, associative, and idempotent, so replicas converge whatever order or duplication they see.
A CRDT is a merge function with three properties, and every guarantee follows from them. Because merge is commutative, associative, and idempotent, two diverged copies reach the same value no matter the arrival order, duplication, or merging replica. The cost is state: the metadata that makes merge correct must travel with the data and never shrinks on its own.
Take a counter first. Each writer owns one slot in a vector, and an increment bumps only that writer's slot. Merging two copies takes the larger value in every slot, and reading the counter sums the slots. Max is commutative, associative, and idempotent, so merging a copy with itself, or with a stale copy that arrives late, changes nothing. A set works the same way, but as two sets: adds and removes. Adding an element writes it to the adds set, removing it writes it to the removes set, and merge is union on both sides. Union never drops an element, so the merge never decides which write came later. It keeps every write, and the read step decides what the user sees.
The abstraction hides intent. Merge preserves every update but cannot know what the user meant. Consider a cart built as adds union removes with no tags. A user deletes eggs on leader one, and that removal has to travel. Before it arrives, the same user re-adds eggs on leader two. Once replicas merge, eggs sit in both sets, and the removal wins. The eggs vanish with no error, no conflict, and no log line. The system is consistent and silently disagrees with the last thing the user did. Unique tags per addition fix this: the removal cancels only the tag it names, so the re-add survives. Tags are not optional once re-adds matter. The cost is permanent. Every tag ever issued and every removal stays in its set, because no merge operation deletes an entry. Tombstones go only after a causal-stability check confirms no replica can still send an older add.
Use a CRDT only when a merged answer is acceptable business behavior. Good fits are counters, sets of independent items, presence, likes, and tag membership. Before you choose one, ask whether a removal may silently cancel a concurrent re-add, and whether that is acceptable. Ask whether any invariant must hold, such as a counter that never exceeds stock. If an invariant must hold, do not use a CRDT; coordinate the write instead. Ask whether a person will later ask why an element is present. If so, keep an audit log beside the merged value. Avoid sequence structures such as lists and collaborative text unless you budget extra design, because a list is an ordering and the algebra fights it. If you need order across writes, use a log with one append point. Count writers before you ship, since metadata grows with them, and schedule tombstone collection after a causal-stability check.
- Writer metadata
- one entry per writer
- Merge cost
- linear in state size
- Tombstone retention
- until causal-stability check
- Operation message
- one update per send
Each writer owns a slot in the version vector, so metadata grows with writers, not with the number of writes.
A merge reads every entry on both sides, so large state makes each sync expensive even when little changed.
A removal marker survives until no replica can still send an add it would cancel.
An op-based CRDT ships one operation, but the transport must deliver it causally without drops or duplicates.
The first design treated replication as a timestamp problem. Each write carried a clock value, and the newest stamp won. The team expected clocks to settle the ordering question, so the design looked finished on paper and passed the simple tests.
The wall arrived with concurrent writes. The stamp imposed an order on writes that nobody had seen in sequence, so a removal could erase an addition that the removing replica never saw. A re-add could also be swallowed by a removal that had already happened on another replica. No test caught it because each replica looked correct alone.
The fix changed the requirement rather than the clocks. Pick a merge function that is commutative, associative and idempotent, so the result does not depend on arrival order. Keep per-writer counters and tombstones, which no merge may delete, so each write survives long enough to be merged. Convergence now came from the function.
The lesson is that convergence belongs to the merge function, not to the transport. The price moves from coordination into memory, since metadata grows with writers and deleted items keep their markers. Teams that chase delivery guarantees first spend effort in the wrong place.