Part VI — The Blueprint · Lesson 11.11
HLD – Google Docs
In one lineTwo people typing in the same paragraph is the entire problem — OT or CRDT is the answer.
Where you've seen itTwo colleagues typing into one sentence, and the result reading correctly for both of them.
Diagram
| Step 1–2 | Scope and scale |
|---|---|
| In scope | rich text editing · multi-user cursors · comments · offline editing · version history |
| Out of scope | export pipeline · sharing permissions UI · print |
| Scale | docs up to ~100k words · 2–20 concurrent editors · sub-100ms local echo is non-negotiable |
How it works
- The document is a data model, not the DOM — a tree of blocks with marks. Rendering derives from it.
- Local echo first: apply, render, then send. Any perceptible delay makes typing feel broken.
- Sync via OT or CRDT over WebSocket (2.4), with an explicit reconnect-and-catch-up path.
- Presence is ephemeral and travels separately from document operations.
- Offline buffers ops locally (9.1) and merges on reconnect — CRDTs make this trivial, OT makes it work with server help.
Trade-offs
| Choice | Cost |
|---|---|
| OT | Compact, mature, server-dependent, tricky to implement |
| CRDT | Offline-friendly, convergent, larger payloads |
| contentEditable | Native input/IME; famously inconsistent across browsers |
| Custom-rendered editor | Full control; you rebuild IME, selection, and a11y |
Accessibility (8.3): rich-text editors are one of the hardest a11y surfaces — announce collaborator changes politely without spamming, keep keyboard shortcuts discoverable, and never move the user's cursor because of a remote edit.
Interview angle
"Two users type in the same sentence. How does it not break?"
- Position indices shift under concurrent edits, so raw last-write-wins loses one of them.
- OT transforms incoming operations against already-applied ones; CRDTs give every character a unique id so merges commute.
- I'd pick based on constraints — OT with an authoritative server, CRDT if offline or peer-to-peer editing is required — and I'd apply locally first so typing never waits on the network.
Recap
- Concurrent text editing is the problem; OT and CRDT are the two real answers.
- Local echo immediately; sync in the background.
- Presence is ephemeral and separate from document history.