← Lessons

quiz vs the machine

Gold1480

System Design

CRDT for Text Deep Dive

How conflict free replicated data types merge text without a central transform.

6 min read · core · beat Gold to climb

What a CRDT is

A conflict free replicated data type is a data structure whose merge operation is automatically consistent. Any two replicas that have seen the same set of edits end up identical, regardless of the order those edits arrived, with no transform step and often no central server.

How text CRDTs work

Each character gets a globally unique identifier that never changes once assigned. Instead of integer positions, the document is an ordered set of these identifiers. Two concurrent inserts at the same spot are ordered deterministically by comparing their ids, so every replica picks the same winner.

The tradeoffs

  • Strength is that merging is associative and commutative, so any order works.
  • Cost is metadata overhead, since each character carries an id and deleted characters often linger as tombstones.

Modern libraries shrink the overhead with block compression that stores runs of consecutive characters under one id range.

Key idea

A text CRDT gives each character a stable unique id so concurrent inserts merge deterministically without any transform.

Check yourself

Answer to earn rating on the learn ladder.

1. What property makes a CRDT merge safe in any order?

2. Why do text CRDTs use unique character identifiers?

3. What is a common cost of CRDTs?