← Course Index

Design Google Docs (Collaborative Editing)

~25 min · Case Studies · DDIA §5 · DesignGurus

Ref
Primary Source
Designing Data-Intensive Applications (DDIA) §5 — "Conflict-Free Replicated Data Types" & SRE Collaborative Editing models

Explores algorithms for conflict resolution in real-time document editing, comparing Operational Transformation (OT) and CRDTs.

The Real-Time Concurrency Challenge

In a standard text editor, saving a file overwrites the previous version. If multiple users edit a shared document simultaneously over the web, overriding fails: User A's save will overwrite User B's edits.
Locks also fail: locking a document for editing prevents true real-time collaboration.

To support real-time editing, the system must receive character insertions and deletions from multiple clients and merge them so that **all users eventually see the exact same document sequence** (Convergence).

Two Collaborative Editing Paradigms

1. Operational Transformation (OT)
Used by Google Docs and Apache Wave.
Operations (Insert/Delete) are represented 
relative to index positions.

A central server sequences all incoming edits, 
re-calculates (transforms) character indexes, 
and broadcasts adjustments to clients.

✓ Low memory footprint.
✗ Hard to implement; requires a single 
  centralized sequencing server.
2. Conflict-Free Replicated Data Types (CRDT)
Used by Figma, Apple Notes, and Yjs.
Characters are treated as distinct mathematical 
objects with globally unique fractional IDs.

Clients apply edits locally and broadcast them. 
Operations merge deterministically in any order, 
without server transformation.

✓ Decoupled: works in peer-to-peer setups.
✗ Higher memory overhead due to metadata.

Operational Transformation Walkthrough

Let's look at a classic OT collision. Document state starts as: "cat".

Initial Document: "cat" Client A: insert 's' at index 0 State: "scat" Client B: insert 's' at index 3 State: "cats" OT Server Receives Client A, updates index of B Insert 's' at index (3 + 1) = 4
Operational Transformation: The server receives Client A's edit, transforms Client B's index, and broadcasts the result so both clients converge on "scats"

Real-Time Architecture Components

Check Your Understanding

1. In collaborative editing, why are traditional database table locks not used?
2. How does Operational Transformation (OT) maintain consistency?
3. What is a key benefit of CRDTs (Conflict-Free Replicated Data Types) compared to OT?