Three people edit the same document offline, then reconnect. A CRDT makes every copy end up identical with no referee. We start with a counter, then text.
Three people edit the same shared document. One has no signal, one has a connection that keeps dropping, and one is fine. Later everyone reconnects, and all three copies must show the exact same text.
Who decides whose edit wins? Some systems use a central server. But there is a trick where nobody needs to decide at all. It is called a CRDT, and we will build it up from the simplest example.
Say you keep a copy of the data on your phone, and a second person keeps one on theirs. Each copy is called a replica. You both edit while offline, and later the copies meet.
Now there are two different versions and no referee. That clash is the problem.
So what rule makes the "after" side possible?
CRDT stands for Conflict-free Replicated Data Type. The 2018 survey by Preguiça, Baquero and Shapiro gives two rules, paraphrased here.
Any copy can be changed without asking the other copies first. And once two copies have received the same set of updates, they end up in the same state, every time.
Notice what is missing: no waiting, no lock, no "ask the server". The rules are baked into the data structure itself. Let's see that with the simplest thing possible.
Three people count how many times a shop was visited. The obvious design is one shared number. But offline, two people both see 5, both add 1, and now they have to merge two 6s. Is it 6 or 7? (It is 7, but the copies cannot know that.)
The fix is the grow-only counter. Each replica owns one slot and only ever adds to their own slot.
| Replica | A's slot | B's slot | C's slot |
|---|---|---|---|
| A, after 2 visits | 2 | 0 | 0 |
| B, after 3 visits | 0 | 3 | 0 |
Now the copies need to meet. How do they merge?
Go slot by slot and keep the larger number. The total is the sum of all slots. Click Next and watch it happen.
A holds 2 0 0 after 2 visits
Notice the merged copy has both replicas' counts. Why does this never break? Taking the max gives the same answer in any order, can be repeated safely, and can be grouped any way. So duplicate and late messages are harmless.
Let us test that with a bad network.
Say B's phone sends its state to A, but the network drops some packets and keeps retrying. With a plain "add" you could count the same update three times, which gives a wrong total. With max, repeats change nothing.
Hit play to watch packets get lost on an unreliable link.
Did you see the lost one? Nothing breaks, because the next copy of B's state carries the same information.
Offline edits just work. Messages can arrive late, twice or out of order.
A grow-only counter can't go down. Subtracting needs a slightly bigger design.
Counters are the easy case. Text is harder.
Numbers are easy because adding commutes (order does not matter). Text is trickier. If the doc reads "hi" and two people both insert at position 2, whose letter goes first? And if you also delete a letter, every position after it shifts.
So "insert at position 2" is a bad instruction. By the time it reaches someone else, position 2 may mean something different.
Give every character a name. Sequence CRDTs give each character its own unique ID, and the ID decides where it sits. Several designs exist, like Treedoc, Logoot and RGA, and the exact rule differs between them. The crdt.tech papers page lists them all.
The shared idea is that an edit means "put this letter between these two IDs", not "at spot 2". IDs don't move when others type, so the instruction stays true on every copy.
If two people insert in the same gap, the design has a fixed tie-break rule, so every copy picks the same order. That rule is the "referee", and it lives inside the data instead of on a server.
I do not know what runs inside it, and I will not guess. What I can say is that crdt.tech describes tools like Google Docs, Trello and Figma as routing communication through a server, while CRDTs do not assume a single server. So the pitch is editing offline and peer to peer.