Skip to main content

Command Palette

Search for a command to run...

A Beginner's Guide to Conflict-Free Replicated Data Types (CRDTs)

Published
5 min read
A Beginner's Guide to Conflict-Free Replicated Data Types (CRDTs)
T

Hi there! I’m Tarun, a Senior Software Engineer with a passion for technology and coding. With experience in Python, Java, and various backend development practices, I’ve spent years honing my skills and working on exciting projects.

On this blog, you’ll find insights, tips, and tutorials on topics ranging from object-oriented programming to tech trends and interview prep. My goal is to share valuable knowledge and practical advice to help fellow developers grow and succeed.

When I’m not coding, you can find me exploring new tech trends, working on personal projects, or enjoying a good cup of coffee.

Thanks for stopping by, and I hope you find my content helpful!

Introduction: Why Conflicts Happen in Distributed Systems

Imagine you and your friend are both editing the same shared to-do list.

  • You add “Buy milk”.

  • At the same time, your friend adds “Buy bread”.

When the system tries to merge these updates, what happens? If not handled carefully, one of the edits might disappear. That’s a conflict.

CRDTs are designed to solve this problem — automatically and mathematically.


The Google Docs Example: Writing Together Without Chaos

Think about Google Docs. You and your friend can type at the same time:

  • You write “Hello”.

  • Your friend writes “World”.

Instead of overwriting each other, Google Docs merges the changes. That’s the magic of conflict-free replication — and CRDTs are one way to achieve it.


What Are CRDTs?

Breaking Down the Definition

CRDT stands for Conflict-free Replicated Data Type.

It’s a special data structure that:

  1. Can be copied across multiple devices (replicas).

  2. Lets each replica update data independently.

  3. Merges all updates automatically without conflicts.

How CRDTs Differ from Traditional Data Structures

  • A normal list or map doesn’t know how to merge independent changes.

  • A CRDT is built with merge rules baked in, so conflicts never happen.


Why Do We Need CRDTs?

Offline-First Applications

Imagine using a notes app on your phone while offline. When you reconnect, CRDTs ensure your edits merge correctly with changes made on other devices.

Real-Time Collaboration

Apps like Notion, Figma, or Google Docs rely on CRDTs (or similar techniques) to let multiple users work together smoothly.

Avoiding Centralized Coordination

CRDTs remove the need for a single “boss server” to decide the final state. Each device can merge independently and still stay consistent.


Types of CRDTs

State-based (Convergent) CRDTs

Each replica sends its entire state to others. Merges happen by applying mathematical rules to reach the same final state.

Operation-based (Commutative) CRDTs

Instead of sending the whole state, replicas send operations (like “insert X” or “delete Y”). Each operation is applied in a way that guarantees no conflicts.


Example 1: Collaborative Text Editing (like Google Docs)

👩 Alice types: “Hello”
👨 Bob types: “World”

Normally, one update might overwrite the other.

How CRDT resolves this conflict:

  • Each character gets a unique identifier (tagged with who added it and when).

  • Alice’s “H” might be (Alice,1), Bob’s “W” might be (Bob,1).

  • CRDT merges both by sorting identifiers, so neither is lost.

The final doc could be:
👉 “HelloWorld” (if Alice’s IDs come first)
👉 Or “WorldHello” (if Bob’s come first)

Either way, both edits survive — no conflict.


Example 2: Shared To-Do List Across Devices

👩 Alice adds: “Buy eggs”
👨 Bob (offline) adds: “Buy bread”

When Bob reconnects, what happens?

How CRDT resolves this conflict:

  • Each item is stored with a unique ID.

  • Even if both edits target the same spot (end of the list), CRDT merges by ID order.

  • Result:

    • Buy eggs

    • Buy bread

If both add “Buy eggs”, CRDT collapses duplicates, keeping only one.

👉 No loss, no confusion — the list remains consistent.


Example 3: Multiplayer Drawing Board

👩 Alice draws a red circle.
👨 Bob draws a blue square at the same time.

How CRDT resolves this conflict:

  • Each stroke is treated as an independent element with a unique ID.

  • When merged, CRDT keeps both the circle and the square.

  • If both draw at the same spot, both shapes remain (overlapping).

👉 CRDT doesn’t delete anyone’s work — it keeps all contributions.


How CRDTs Guarantee Conflict-Free Merges

CRDTs rely on three mathematical properties:

  1. Idempotent → Applying the same update multiple times doesn’t break things.

  2. Commutative → Order of updates doesn’t matter.

  3. Associative → Merging in groups gives the same result as merging step by step.

This means that no matter when or where edits are made, merging always leads to the same final state.


CRDTs vs. Operational Transformation (OT)

Both CRDTs and OT (used in Google Docs) solve conflicts in collaboration.

FeatureCRDTOT
Conflict HandlingAutomatic, mathematicalTransformation rules
Offline SupportExcellentMore complex
ComplexityLowerHigher
PopularityGrowing (Automerge, Yjs)Widely used (Google Docs)

Real-World Use Cases of CRDTs

Messaging Apps (WhatsApp, Slack)

Messages from multiple devices stay in sync without conflict.

Collaborative Apps (Notion, Figma, Google Docs)

Multiple users can type, draw, or edit at the same time.

Distributed Databases

Databases like Riak DT use CRDTs to keep replicas consistent.


  • Automerge (JavaScript) → Build collaborative apps.

  • Yjs (JavaScript) → High-performance CRDTs for text and more.

  • Riak DT (Erlang) → CRDT support for distributed databases.


FAQs on CRDTs

Q1: Why are CRDTs called “conflict-free”?
Because they’re designed so that conflicts mathematically can’t happen.

Q2: Are CRDTs only for text editing?
No — they work for lists, sets, counters, maps, and more.

Q3: Do CRDTs need the internet to work?
No. They shine in offline-first apps that later sync online.

Q4: Are CRDTs the same as Operational Transformation (OT)?
No, they’re different approaches. CRDTs use math-based merges, OT uses transformation rules.

Q5: Do all collaborative apps use CRDTs?
Not all. Some use OT, others use CRDTs. It depends on system design.

Q6: What’s a simple analogy for CRDTs?
It’s like two people adding toppings to a pizza at the same time — instead of fighting, both toppings end up on the final pizza.


Conclusion: Why CRDTs Are the Future of Collaboration

CRDTs solve one of the hardest problems in distributed systems: merging simultaneous changes without conflicts.

  • They work offline and sync later.

  • They allow real-time collaboration.

  • They guarantee consistency without a central authority.

So the next time you edit a Google Doc, manage a shared to-do list, or draw on a collaborative whiteboard — remember: CRDTs are quietly making sure nothing you do gets lost.