Conflict resolution and convergence
When replicas accept concurrent changes, a deterministic rule must merge them so every replica ends in the same state without losing intent.
Concurrency
Learn it
Two people type into the same sentence at once; a phone edits a note offline while a laptop edits it online. Both changes were made against the same starting state and both are legitimate. Applied naively one after the other, the text can be garbled or one change silently dropped.
A convergent merge rule makes every replica end in the same state.
Three approaches:
- Last writer wins (LWW): keep the change with the latest timestamp or version. Simple and convergent, but it discards the other change. Fine for a profile photo; wrong for a shared paragraph.
- Operational transformation (OT): clients send operations tagged with the revision they were based on. A central sequencer transforms each against the ops it missed ("3 characters were inserted before position 12, so this is now 15"), then broadcasts it.
- CRDTs: operations commute: any order gives the same result. Each character gets a stable identity, so "insert after (alice, 41)" means the same everywhere. No central authority is needed, which suits offline editing; the cost is metadata.
Check
Text is "abc". Alice inserts "X" at position 0; concurrently Bob deletes position 2 ("c"). With OT, after Alice's insert is applied first, what does Bob's delete become?All three guarantee convergence: everyone ends with the same text. Intent preservation, the merged result reflecting what each person meant, is where they differ, and no algorithm can fully decide it. Two people rewriting the same sentence still need a human.
Quick reference
The same ideas, condensed for revision.
How it goes wrong
- LWW on rich content
- One user's paragraph silently disappears.
- Non-convergence
- A transformation bug or missed operation leaves replicas permanently different; detect with periodic checksums.
- Unbounded metadata
- CRDT tombstones accumulate for documents with long histories.
Instead, consider
- Locking (one editor at a time)
- Concurrent editing is rare, and simplicity and predictability matter more than fluid collaboration.
- Manual merge (git-style)
- Changes are large and infrequent, and users can review conflicts.
In practice
- ShareDB, ot.js
- OT with a central server.
- Yjs, Automerge
- Sequence and map CRDTs with sync protocols.
- LWW registers
- Per-field last-writer-wins, common in mobile sync products.
It assumes
- Every replica eventually receives every operation (delivery is reliable, possibly duplicated).
- Operations are applied idempotently. Duplicates are detected by operation ID.
- For OT: a single authority orders operations per document.
Explain it in your own words
Where you practise it
Further reading
Engineers describing it in systems they run.
- How Figma's multiplayer technology works
Figma · Evan Wallace · Post, Oct 2019
Why a central server per document let Figma avoid most of the machinery of operational transforms, and how ordering works when anyone can insert anywhere.
- How Discord Stores Billions of Messages
Discord · Stanislav Vishnevskiy · Post, Jan 2017
Choosing a database and a partition key for chat history, and the surprises that followed: tombstones, and an edit racing a delete.
Related concepts
- Ordering
There is no global 'now' in a distributed system. Order exists only where something assigns it, so decide which order you need and who assigns it.
- Append-only logs
Recording changes as an ordered, immutable sequence of facts, from which current state, history and replicas can be derived.
- Idempotency
Designing an operation so that performing it twice has the same effect as performing it once, which is what makes retries safe.
- Replication
Keeping copies of data on several machines for durability, read capacity and locality, and living with copies that briefly disagree.