Collaboration
Collaborative editor - two carets in one paragraph
How two people type into one document at the same time without either of them losing a character.
The first act plays here. Owned once with credits, never a subscription.
What this board gets wrong on purpose
The tension
An open document is one mutable object in one process, mutated synchronously and written to the database 250 ms later, debounced - which is what makes a keystroke appear in 40 ms and what makes every deploy a data-loss risk. The board answers with a SIGTERM flush that writes every dirty room before the process exits and refuses to exit zero if any of them failed, and that answer is only as good as the grace period: a SIGKILL, an OOM or a node that simply vanishes takes the last 250 ms of every room on it. Nor does the flush help the document that is TOO BIG to save, which is refused at write time and carries on being edited in memory against a database that will never hold it. And the room is pinned to one process by construction, so there is no second replica to fail over to - a rolling deploy is a planned disconnection of every editor in the fleet, timed rather than avoided.
Practise this as an interview
Take Collaborative editor - two carets in one paragraph as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.
Start here
Why this design
A collaborative editor is the cleanest test of whether you understand concurrent state: every client has already applied its own edit before the server sees it, so the system is about reconciling divergence rather than preventing it. Interviewers use it to probe the OT-versus-CRDT decision, ordering, and what "acknowledged" means when the truth lives in one process’s memory. Real teams (Google Docs, Figma, Notion) live with the operational consequence - a room pinned to a process makes every deploy a planned disconnection.
What you will learn
- Why local echo forces optimistic replication, and how an operation carries a base revision so the server can rebase it onto the head.
- How operational transformation depends on one process seeing every op in one total order - and why that pins each document to a single room.
- What a CRDT costs instead: per-character ids and tombstones that turn a 12 KB document into roughly 320 KB over its life.
- Why presence is a separate, never-persisted pipe that carries about twice as many frames as the edits themselves.
- How op log retention decides whether an offline client’s edits can be merged at all - a storage choice that is really a correctness choice.
- How a debounced, revision-guarded flush and a SIGTERM drain bound data loss to the last 250 ms, and what a SIGKILL still costs.
How to read this board
- Diagram, top row left to right: PEOPLE, then THE CLIENT · APPLIES FIRST (local echo and the pending-ops queue), then THE ROOM · ONE WRITER, NOTHING AWAITED (edge socket, document server, transform, room doc in RAM).
- Then the middle band, FAN-OUT, PRESENCE AND THE EDIT THAT ARRIVED LATE: the broadcast that doubles as the ack, the caret channel, and the reconnect-and-rebase path for Editor B.
- Then the right-hand column: DURABILITY · OFF THE HOT PATH ON PURPOSE and COMPACTION · A LOG THAT NEVER ENDS. Press play for the nine-step walkthrough.
- Page 1 · Requirements - the questions that decide OT or CRDT before anything is drawn, and the 16 ms local-echo target.
- Pages 2 and 3 · Capacity and Storage - 288k ops/s and a million presence frames/s on eighteen machines; a 1.5 PB op log that snapshots cut to 24 TB, and the CRDT priced alongside.
- Page 4 · Availability - the room process as the structural single point of failure, and what degrades rather than dies.
- Page 5 · How it works - one character end to end, then the offline edit; Page 6 · Deployment - drain, flush, jittered reconnect.
- Finally the DATA MODEL at the bottom: five tables, and why the op log dwarfs the documents it describes.
1 · Requirements
Ask these before drawing anything
- Must an edit appear instantly on the machine that made it? If yes - and it is always yes - then every client is already divergent and the whole board is about reconciling, not about preventing.
- How many people may edit one document at once? Two is a different system from two hundred, and two hundred is mostly a presence problem rather than an editing one.
- Is the document plain text, rich text, or a tree with attributes? OT on a flat string is a well-understood ninety lines; OT on a tree with formatting spans is where implementations go to die.
- Must edits made offline be accepted, or may they be refused? "Accepted" means keeping enough history to transform them forward, which sets the op log retention, which sets the storage bill.
- Does the product need per-character attribution - who typed this word? That is a different data structure from "who changed this document", and asking for it later is a rewrite.
- How long is a document expected to live? A CRDT accumulates metadata per character that survives deletion, so a five-year document is a different size from a five-day one.
- Is there a server at all? Peer-to-peer or local-first removes the ordering authority and forces a CRDT. Saying "we have a server" is the decision that makes OT available.
- What is the largest document anyone may open? There is always a limit and it is always found by a user rather than written down.
Functional
- Two or more people edit one document simultaneously and every one of them converges on the same text.
- An edit appears on the machine that made it before any network round trip.
- Each participant sees the others’ carets and selections, labelled and coloured stably.
- An edit made while disconnected is not lost: on reconnect it is transformed onto the current head and applied.
- A document can be reverted to any earlier point for as long as the op log retains it.
- A view-only participant sees live changes and cannot send any.
Non-functional
- Local echo: under 16 ms, which is one frame. This is not negotiable and it is why local-first is a requirement, not a design.
- Remote application: p50 under 120 ms, p99 under 400 ms, same region.
- Convergence: after any sequence of concurrent edits and any delivery order, all replicas that have seen the same set of ops hold the same document. This is a correctness property, not a latency one.
- 99.95% availability for opening and editing. Presence has no availability target at all.
- Durability: an acknowledged edit survives a clean shutdown. An acknowledged edit does NOT currently survive a hard kill of the process holding the room, and that gap is stated rather than hidden.
Out of scope
- Comments and suggestions, which anchor to ranges that move and are their own board.
- Offline-first mobile with multi-day divergence.
- End-to-end encryption, which removes the server’s ability to transform and therefore forces a CRDT.
The rest of this board
Available on Tier Slate
This page publishes the question. The answer — 5 more written pages, a 9-step narrated walkthrough and a 5-table schema — is the board itself, and it opens in Tierslate.
- 5written pages
- 9walkthrough steps
- 5tables35 columns
5 pages behind this one
- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan