OT vs CRDT: what is the difference for collaborative editing?
AdvancedDesign patterns and architecture interview questionBy UIRound, updated 23 November 2026
Short answer
Operational transformation (OT) and CRDTs both let several people edit the same document and end up with identical text. OT sends edits as position-based operations and rewrites ("transforms") each one against concurrent edits, which in practice needs a central server to order them, as Google Docs does. A CRDT is a data structure whose merge always converges in any order, so replicas can sync without a coordinator, at the cost of extra metadata.
The problem both solve
Two people open "abcde". Alice inserts A at position 3. At the same time Bob inserts B at position 3. Each applies their own edit locally first, so the editor feels instant, and then receives the other's edit.
If each side naively applies the other's operation, Alice gets abcBAde and Bob gets abcABde. The documents have diverged, and every later edit will make it worse. Positions are the problem: "position 3" means a different place once someone else has inserted text before it.
Both techniques guarantee convergence: once everyone has seen the same set of edits, everyone has the same document. They differ in where the work happens.
Operational transformation
In OT an edit is an operation on positions: retain 3, insert "A", retain 2. When two operations were made on the same version, a transform(a, b) function returns adjusted versions a' and b' so that applying a then b' gives the same result as b then a':
// Both made on "abcde". The tie at the same position must be broken the same way everywhere.
const a = insertAt(3, "A"); // Alice
const b = insertAt(3, "B"); // Bob
const [aPrime, bPrime] = transform(a, b);
bPrime.apply(a.apply("abcde")); // "abcABde"
aPrime.apply(b.apply("abcde")); // "abcABde"A typical OT system works like this:
- The server keeps the document and a numbered history of operations.
- A client sends its operation with the revision it was made on.
- The server transforms it against every operation accepted since that revision, applies it, appends it to the history and broadcasts it.
- Each client keeps at most one operation in flight and buffers further edits. Incoming server operations are transformed against the in-flight and buffered ones before being applied.
The central server is what keeps OT manageable. With one authority choosing a single order, transforms only need to satisfy one property (the two paths give the same result). Without a server, in peer-to-peer setups, transforms must also hold up when three or more operations are reordered, and a number of published algorithms were later shown to break in exactly that case.
Who uses it: Google Docs is the best-known OT system. ShareDB provides OT for JSON documents, and CKEditor 5's real-time collaboration is built on OT. ProseMirror's collab module uses a similar central-authority model in which clients rebase their pending steps onto the server's order.
Strengths: operations are small, the document itself carries no extra metadata, and the server is a natural place to check permissions, validate edits and store history.
Weaknesses: you need a transform for every pair of operation types, and rich text, tables and nested structures multiply them. The server is in the critical path for every edit, and long offline sessions mean transforming a large batch of operations against a large history on reconnect.
CRDTs
A CRDT (conflict-free replicated data type) avoids positions. In a sequence CRDT, every character gets a unique id, for example (clientId, counter), and an insert says "after the character with id X", not "at position 3". Deletes mark a character as removed instead of erasing it. Because ids never shift, operations commute: apply them in any order, any number of times, and every replica ends in the same state.
import * as Y from "yjs";
const alice = new Y.Doc();
const bob = new Y.Doc();
alice.getText("body").insert(0, "abcde");
Y.applyUpdate(bob, Y.encodeStateAsUpdate(alice));
alice.getText("body").insert(3, "A");
bob.getText("body").insert(3, "B");
// Exchange updates in either order, over any transport.
Y.applyUpdate(alice, Y.encodeStateAsUpdate(bob));
Y.applyUpdate(bob, Y.encodeStateAsUpdate(alice));
alice.getText("body").toString() === bob.getText("body").toString(); // trueBoth replicas end with the same string; which of A and B comes first is decided by a deterministic tie-break on the client ids.
Who uses it: Yjs (based on the YATA algorithm) and Automerge are the main libraries, with editor bindings for ProseMirror, Tiptap, Lexical, CodeMirror and Monaco. Yjs separates the document from "providers" that move updates: y-websocket through a server, y-webrtc peer to peer, y-indexeddb for local persistence.
Strengths: no coordinator is required, so offline editing for days, peer-to-peer sync and local-first apps all work naturally. Merging is the same code whether the other edit arrived a millisecond or a week ago. You can still use a server, and most products do, but only as a relay and store, not as the thing that makes edits correct.
Weaknesses:
- Metadata. Every character needs an id and position information. Libraries compress this heavily (Yjs merges runs of characters typed by one client into one item), but the document state is still larger than the plain text.
- Tombstones. Deleted characters must be remembered so that a late insert "after X" still has an X to anchor to. They are cheap individually and accumulate over a document's life.
- Validation is harder. With no single order, a server cannot simply reject an edit the way an OT server can. Permission checks happen on who may send updates at all, or on a server that applies updates and checks the result.
- Intent anomalies. Some sequence CRDTs can interleave two users' concurrently typed words character by character. Newer algorithms, such as Fugue (2023), were designed to minimise this.
The offline-first sync guide places both techniques among simpler conflict strategies like last-write-wins and version checks.
Side by side
| OT | CRDT | |
|---|---|---|
| Edits refer to | Positions | Unique element ids |
| Needs a central server for correctness | In practice, yes | No |
| Offline and peer-to-peer | Possible but painful | Natural |
| Extra data in the document | Little | Ids and tombstones |
| Server-side validation | Easy: the server orders and can reject | Harder |
| Implementation effort | Transform functions per op pair | Use a library; writing one is hard |
| Known examples | Google Docs, ShareDB, CKEditor 5 | Yjs, Automerge |
When to pick each
- Pick OT, or a server-ordered model, when every client is online, a server already sits in the middle, and you need strong server control: permissions per section, validation, audit history. A server-authoritative design also makes undo and moderation simpler to reason about.
- Pick a CRDT library when users edit offline for long periods, devices sync peer to peer, the app is local-first, or you want to add collaboration without building and operating a transform server.
- Use neither when the data is not text. Forms, settings and records with independent fields are well served by per-field last-write-wins plus version checks. Ordered lists like Kanban columns are usually fine with fractional indexing. Figma has written that its multiplayer system is server-authoritative and only inspired by CRDTs, because a design file is mostly objects with properties, not long runs of text.
In an interview you rarely implement either. Name the trade-off, pick one for the product in front of you and say what it costs. To understand what happens inside, build OT for plain text and an RGA text CRDT, then put them in context in the Google Docs design question.
Follow-up questions interviewers ask
Is a CRDT always better because it does not need a server?
No. Most CRDT products still run a server for persistence, auth and fan-out. The difference is that the server is not needed to make merges correct. If you need the server to reject or reshape edits, OT's single order is an advantage, not a limitation.
How do remote cursors and selections work?
They are not part of the document. Send them as ephemeral presence state (Yjs calls it awareness), throttled, and anchor them to stable positions: in a CRDT, a relative position tied to an element id, so a cursor stays next to the same character while others type. A collaborative rich-text editor with remote cursors builds this.
How does undo work in a collaborative editor?
Undo must revert only your own changes, not the last change in the document. In OT you invert your operation and transform it against everything since. In Yjs, Y.UndoManager tracks changes by origin so it undoes only the local user's edits.
What are tombstones and can you remove them?
They are markers for deleted elements kept so that concurrent operations can still find their anchors. You can garbage-collect them once every replica has seen the delete, which is easy with a server that knows all clients and hard in open peer-to-peer systems.
Are simple CRDTs useful outside text?
Yes. Counters, sets and last-writer-wins maps are CRDTs too, and they are much simpler than text. State-based CRDTs: a PN-counter, an OR-set and an LWW map shows the merge rules.
Sources
Practise it in code
Interviewers rarely stop at the definition. These questions open in an editor with tests.
- Build operational transformation for plain text:
compose,transform, a server history and a client that buffers editsHard70 min - Implement a text CRDT (RGA) for collaborative editingHard60 min
- Build state-based CRDTs: a PN-counter, an add-wins OR-Set without tombstones and a last-writer-wins mapHard60 min
- Design Google Docs: collaborative editing with CRDT or OT, cursors, and conflict resolutionHard60 min
- Build a collaborative rich-text editor with remote cursors and offline synchronizationHard90 min
- Design a collaborative whiteboard like Miro: infinite canvas, shapes, presence, conflict-free edits and performanceHard60 min