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.
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.
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
More boards
Several people editing one thing without losing an edit.