CRDTs — Conflict-Free Replicated Data Types
Merging concurrent edits without losing data
Two users edit the same doc offline; two replicas take writes during a partition. When they reconnect, naive last-write-wins discards one side. CRDTs (Conflict-free Replicated Data Types) are data structures engineered so that concurrent updates merge automatically into the same final state, no matter the order — the basis of Google Docs-style collaboration, Figma, and distributed counters.
Why they always converge
The merge operation is designed to be commutative, associative, and idempotent — so applying merges in any order, even duplicated, yields the same result. The canonical example, a grow-only counter (G-Counter): each replica only ever increments its own slot in a vector; to merge, take the per-node maximum, and the count is the sum. No increment is ever lost, because no replica overwrites another's slot.
| CRDT | For |
|---|---|
| G-Counter / PN-Counter | counters (likes, views) that must not lose increments |
| LWW-Register | a single value, last-writer-wins by timestamp (accepts loss) |
| OR-Set | add/remove sets where concurrent add+remove resolve deterministically |
| Sequence CRDTs (RGA, Logoot) | collaborative text — concurrent inserts keep a stable order |
When to reach for them
CRDTs shine for multi-master / offline-first / collaborative systems on the eventual-consistency end of the spectrum — they buy automatic, lossless convergence. The cost is metadata overhead (tombstones, per-node vectors) that can grow. The alternative for text, Operational Transformation (OT, classic Google Docs), is powerful but needs a central server to transform ops; CRDTs are simpler to decentralize.
Takeaways
- CRDTs merge concurrent updates losslessly because the merge is commutative/associative/idempotent.
- G-Counter = per-node slots, merge by max; OR-Set and sequence CRDTs handle sets and collaborative text.
- Best for offline-first / multi-master / collaborative on the eventual-consistency end; cost is metadata growth.
Re-authored for this guide; G-Counter merge diagram hand-authored as SVG. Follows Shapiro et al. (CRDTs) and the Automerge/Yjs literature. See also: The Consistency Spectrum, Time/Clocks (vector clocks), Replication Lag.
🤖 Don't fully get this? Learn it with Claude
Stuck on CRDTs — Conflict-Free Replicated Data Types? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.
Build the mental picture, not memorization.
I just read a lesson on **CRDTs — Conflict-Free Replicated Data Types** (System Design) and want to truly understand it. Explain CRDTs — Conflict-Free Replicated Data Types from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Socratic — adapts to where you're stuck.
Teach me **CRDTs — Conflict-Free Replicated Data Types** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Active recall exposes what you missed.
Quiz me on **CRDTs — Conflict-Free Replicated Data Types** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Intuition + hook + flashcards for long-term memory.
Help me remember **CRDTs — Conflict-Free Replicated Data Types** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.