Video in progress
You're building a Google Docs-style collaborative editing feature. Which of OT and CRDT do you choose to resolve conflicts, and what does the transport look like?
OT relies on a central server to order operations and is well studied for text, but it's hard to implement correctly. CRDT merges without a center and supports offline mode well, but it has a metadata and memory cost. The transport is WebSocket and an operation log in both cases.
📖 Answer
The core problem: two users change the same text at the same time, operations arrive in different orders, and in the end everyone must see the same document.
Operational Transformation. Each operation (insert(5, "a")) goes to the server. The server orders them and transforms each incoming operation against the earlier ones (shifts positions). The document is compact and operations are small. But the transform functions are very hard for complex document types (tables, lists, formatting), and everything depends on central ordering. Merging the long history of a client that was offline is heavy.
CRDT. Each character or element has a unique ID and ordering information. Even if operations arrive in any order, the result is the same: a mathematical guarantee. The server stays a simple relay and store. Offline edits merge naturally. The cost is metadata: deleted elements stay as "tombstones", the document grows over time, and sometimes compaction is needed.
Today I lean toward CRDT for a new project, because there are ready, tested libraries (mostly in the JS world) and the offline requirement almost always shows up. But in a Java backend you may have to reimplement the CRDT logic yourself, which is a serious risk. Sometimes the server only stores the updates (binary blobs) and leaves the merging to the client.
Transport:
- WebSocket, each document is a "room". The gateway routes by document, with one document on one node where possible;
- an operation log (append-only), each entry with a
seq. A new client gets a snapshot plus the log tail; - a snapshot now and then, to truncate the log;
- cursors and "who is doing what" go on a separate channel that isn't stored and can be lost.
The last point matters: if you send cursor positions with the same reliability as document operations, the log fills up with useless noise.
Sign up to mark studied questions and save your progress.