System Design · Interview breakdown · Free article
Design a Collaborative Document Editor (Google Docs)
Let two people type into the same line and end with the same text, keep editing through a train tunnel, say Saved only when it is true, move a document to a new server without losing an edit, open a three-year-old document in a moment, and serve an all-hands of 2,000. Built one step at a time, with experiments you can run.
A collaborative document editor lets several people edit one document at the same time, each seeing the others’ changes within a moment. Google Docs is the best-known one. Each browser shows a keystroke at once and sends it as a small edit, such as “insert X at position 2, typed against revision 40”. One server owns each document. It puts every edit into one order and rewrites a late edit so it still lands where its author meant it, which is operational transformation. It writes the edit to a log before it says Saved, and sends it to everyone else. A browser keeps one edit in flight and resends it under the same ID after a lost reply, so nothing is written twice. The log itself refuses a second revision 81, so a server that paused and lost its lease cannot write a second revision beside the new owner’s. Opening loads the newest snapshot and at most 999 edits after it. Cursors ride the same connection and are never stored. People who only watch get their updates from relays.
Difficulty: Hard. Reported in interviews at Amazon, Meta, Google, Fountain. Also asked as Design Google Docs, Design a real-time collaborative editor, Design a collaborative code editor, Design Notion collaboration.
How do you design Google Docs?
A collaborative document editor lets several people edit the same document at the same time. Each person sees the others’ typing appear within a moment, with their cursors moving in the text. Google Docs is the best-known example. Microsoft Word for the web and Notion let people edit together too.
- Create: Launch plan · Share. Who may edit is checked on every edit, not once when the page opens.
- Type: Hana types “Friday”. Each letter appears before any server has seen it.
- Together: Kenji types, same line. Two edits to one gap must land in one order on every screen.
- Offline: Offline · 12 pending. Edits typed in a tunnel must merge when the train comes out.
- History: Version: last Tuesday. A document with two million edits must still open in a moment.
Picture Hana and Kenji writing a launch plan together. Hana is at her desk and Kenji is on a train. At 10:02 they both start typing into the same sentence. Neither waits for the other, and neither should have to. Each letter appears on the screen of the person who typed it at once, and on the other’s screen a moment later. When they stop, both screens must show the same text, with nothing either of them typed missing.
Interviewers like this problem because the first answer sounds finished: send each change over a WebSocket, save it in a database, and forward it to everyone else. All of that is right, and the hard part is still missing. Two people who type at the same moment have each changed the text the other’s edit was aimed at. Merging those edits so every screen agrees is the problem, and it has a long history of published answers that turned out to be wrong.
Here is the design in brief. Each browser shows a keystroke at once and sends it as a small edit: “insert X at position 2, typed against revision 40”. One server owns each document. It puts every edit into one order and rewrites a late edit so it still lands where its author meant it. Then it writes the edit to a log and sends it to everyone else. Opening a document loads a recent snapshot of its text and the edits after it.
The rest of this page is about the moments that design has to survive.
The first is two people typing into the same gap. Take the simplest line there is, ABCD. Hana types X between B and C. Kenji, before her X reaches him, types Y into the same gap. If each browser inserts the other’s letter at the position it was sent with, Hana ends up with ABYXCD and Kenji with ABXYCD. Nothing errors. The two screens disagree, and nothing will bring them back together.
The second is a reply that never arrives. Hana types an exclamation mark, the server writes it, and her Wi-Fi drops before the server’s answer reaches her. Her browser does not know whether the edit was saved. What it does next decides whether the document says “Plan!” or “Plan!!”.
What is the interviewer testing?
Most candidates draw browsers, a WebSocket server and a database, and a mid-level answer can stop there. The interviewer then pushes on what that picture assumes. What happens when two people type into the same gap at the same moment? Why does the design need one server per document? What does Saved mean when a reply is lost? What happens when that server stops, or pauses and comes back? How does a document with millions of edits open quickly? What about a document 2,000 people have open?
A senior answer merges edits by transforming them through one server, keeps one edit in flight, and says Saved only after the write. A staff answer explains why operational transformation needs that server, and when a CRDT is the better tool despite its cost. It also shows how the log itself stops two servers from both owning a document.
Spend most of the deep-dive time on merging and on ownership. Saving, snapshots and the crowded document are the usual follow-ups. How to run a round has the time plan for a 45 to 60 minute round and a 15-minute screen.
What should you ask before drawing anything?
Four questions change the design. Ask them in the first two minutes. If the interviewer leaves one open, say your assumption out loud.
- What kind of document?
- Assume text with simple formatting: bold, italics, headings and lists. Spreadsheets and drawings merge differently, and tables and images are a follow-up.
- How many people edit one document at once?
- Assume up to 100 editing, and more who only watch. Google Docs lets up to 100 people work in a file at the same time, and sends bigger audiences to a published copy. Ask whether a document ever has an audience of thousands, such as a company meeting.
- Must editing work offline?
- Assume yes, for a train tunnel or a flight: minutes to days. Ask how long. A laptop that comes back after six weeks is a different problem from one back after six minutes.
- What does Saved promise?
- Assume Saved means the edit survives a server crash. Ask whether it must also survive losing a whole region, because that costs latency on every edit.
Functional requirements
1. Create a doc; share to view or edit 2. Edit at once; see others within a moment 3. See who is here and their cursors 4. Keep typing offline; catch up after 5. Version history; restore an old one out: comments, tables, search, encryption
Say it, don’t write it: Everyone types at once, and every screen must end on the same text.
- Create a document and share it with people, each allowed to view or to edit.
- Several people edit the same document at once, and each sees the others’ changes within a moment.
- See who else has the document open, and where each person’s cursor is.
- Keep typing through a dropped connection, and catch up when it returns.
- See earlier versions of the document, and restore one.
Out of scope
- Comments and suggested edits
- Tables, images and page layout
- Spreadsheets and slides
- Search across documents
- End-to-end encryption
The second requirement carries the problem. The other four are ordinary features until two people type at once, and then each of them has to agree with it. A restored version is a new edit that everyone must merge. A cursor sits at a position that moves when someone types before it. An offline edit is a very late edit.
Non-functional requirements
• Own typing on screen in one frame, 16 ms • Others see it within 200 ms at p95 • Every copy ends on the same text • Saved = written; survives a server crash • Up to 100 editors per doc, more watching • 2M people online, 500k typing: 1M msgs/s
Say it, don’t write it: Typing never waits for the network; Saved always does.
- Your own typing never waits for the network. A letter appears in the next frame, about 16 ms at 60 frames a second.
- Other people see an edit within 200 ms, 95% of the time, in the same region. That is the p95.
- Once everyone stops typing, every copy of the document shows the same text.
- Saved means written down in a way that survives a server crash.
- Up to 100 people edit one document at once, and more may watch.
- 2 million people have a document open at the busiest hour.
Two numbers decide the shape of the design, so work them out now.
The first is the whole fleet. Say 2 million people have a document open at the busiest hour, and a quarter of them, 500,000, are typing. A typist averages about 2 messages a second, because people type in bursts and spend most of their time reading and thinking. That is 500,000 × 2 = 1,000,000 messages a second, a million. No single server can put a million edits a second into one order. Nor does it need to, because edits only need ordering within one document.
The second is one document. Ten people typing at 2 messages a second is 10 × 2 = 20 edits a second. Even 100 editors make 200. One server can order that easily. So the design splits the work by document: every edit to one document goes to the one server that owns it, and each server owns thousands of documents. The fleet grows by adding servers, and no document is ever split. Percentiles explains why the latency target is a p95 rather than an average.
Core entities
Document(id, title, owner, head_rev) Access(doc_id, user_id, role) Edit(doc_id, rev, client, seq, ops) Snapshot(doc_id, rev, text) Cursor(doc, user, pos): memory only
Say it, don’t write it: An edit has a revision, and a client ID with a sequence number.
Follow one keystroke through the records. Hana opens the launch plan, a document with an ID, a title, an owner, and a head revision: the number of the last edit it holds, 82. An access row says Hana may edit it.
She types an exclamation mark after the heading “Plan”. Her browser makes an edit: insert “!” at position 4. It labels the edit with her browser’s client ID and its own sequence number, so this edit is h:7, the seventh from Hana’s browser. It also records the revision it was typed against, 82. The server writes it as revision 83. From then on the edit is (document, revision 83), and it is also (document, h:7), which is how a resend of the same edit is recognised.
A snapshot is the whole text at one revision, kept so that opening the document does not mean replaying every edit since it was created. A cursor is where each person’s caret is. It lives only in the server’s memory.
| Record | What it holds | Why it is separate |
|---|---|---|
| Document | ID, title, owner, head revision | What people list, share and open |
| Access | Document, user, view or edit | Checked on every edit, not only on open |
| Edit | Revision, client ID, sequence number, the change | The log every copy is rebuilt from |
| Snapshot | The text at one revision | Opening without replaying everything |
| Cursor | Person, position | Changes many times a second and may be lost |
The one distinction that matters: an edit must never be lost, and a cursor may be. If the server restarts, every cursor disappears for a second and comes back when each browser sends it again. If an edit disappears, somebody’s work is gone.
API
POST /docs {title} → {doc_id}
PUT /docs/{id}/access {user, role}
GET /docs/{id} → {text, rev: 82}
WS /docs/{id}: edit{seq, base_rev, ops}
→ ack{seq,rev} · remote{rev,client,seq,ops}
GET /docs/{id}/versions?at=…Say it, don’t write it: Plain HTTP for documents; one WebSocket per open document for edits.
Creating, sharing and listing documents are ordinary HTTP calls. Editing uses a WebSocket, a connection that stays open so the server can send Kenji’s letters to Hana the moment they arrive, without her browser asking.
| Call | Returns | Why it looks like this |
|---|---|---|
POST /docs {title: "Launch plan"} | 201 {doc_id: 42} | The creator becomes the owner |
PUT /docs/42/access {user: "kenji", role: "edit"} | 200 | Checked again on every edit, so removing someone takes effect at once |
GET /docs/42 | {text, rev: 82} | The text and the revision it is at, so the browser knows what its first edits are typed against |
edit {seq: 7, base_rev: 82, ops: [insert "!" at 4]} | ack {seq: 7, rev: 83} | Sent over the WebSocket; the sequence number lets a resend be recognised |
| (from the server) | remote {rev: 84, client: "k", seq: 12, ops: [insert "Y" at 3]} | Every edit, already put in order, with its author’s client ID and sequence number, so an author recognises its own |
cursor {pos: 5} | forwarded to the others | Never written down |
GET /docs/42/versions?at=2026-09-22T16:20 | the text at that moment | Built from a snapshot and the edits after it |
Two details are there on purpose. The edit carries base_rev, the revision it was typed against, because the server needs to know which edits it has not seen. And it carries the browser’s own sequence number, so that an edit sent twice is written once.
Step 1: create, share and open a document
Hana creates the launch plan. Her browser calls the document API, which writes a row in the documents database, PostgreSQL here, with Hana as owner. It stores an empty text as the document’s first snapshot. She shares it with Kenji as an editor, which writes an access row.
When Kenji opens it, the API checks his access and returns the text and its revision. For now the text is one stored copy.
The interactive version of this example is available when JavaScript loads.
This is enough for one person at a time. It is also where most of what matters later is decided. Every document has an owner, a list of who may edit, and a revision number that only goes up.
Step 2: edit together through one server per document
Hana and Kenji both open the launch plan. Each browser opens a WebSocket to a gateway, a server whose job is to hold connections. The gateway sends everything about document 42 to the one document server that owns it. For now, say each gateway picks that server by hashing the document ID. The failover deep dive shows why that is not enough.
Hana types a letter. Her browser shows it at once, then sends the edit with the revision it was typed against. The document server gives it the next revision number and appends it to the edit log, a PostgreSQL table with one row per edit. Then it sends the edit to Kenji and tells Hana it is saved. Kenji’s browser applies it. Every so often the server writes a snapshot of the whole text to object storage, so that opening the document does not mean replaying the whole log.
The gateways are sized by connections, not by edits. Two million people with a document open means 2 million WebSockets. At, say, 100,000 connections a gateway, that is 2,000,000 ÷ 100,000 = 20 gateways, plus spare ones. When one fails, its 100,000 browsers reconnect to the others, each after a short random wait, so they arrive spread over several seconds instead of all at once.
The log is sized by edits. A million a second is more than one PostgreSQL database takes. So the log is split by document ID across 64 databases, about 1,000,000 ÷ 64 = 15,625 writes a second each. Every edit of one document lands in the same database. A document with nobody in it is written to a snapshot and dropped from its server’s memory, and the next person to open it loads it again.
The interactive version of this example is available when JavaScript loads.
When Kenji’s train goes into a tunnel, his browser keeps what he types in a list of pending edits, stored on his laptop. When the connection returns, the browser tells the server the last revision it has, 90 say. The server sends every edit after 90, and the browser sends its pending edits. How those two sets of edits are merged is the first two deep dives.
Step 3: cursors and past versions
Kenji wants to see where Hana is typing. Her browser sends her cursor position over the same WebSocket, and the document server forwards it to everyone else in the document. It keeps the latest position of each person in memory and never writes it to the log. A cursor changes many times a second, and nobody needs yesterday’s.
A cursor is a position in the text, so it moves when someone types before it. If Hana’s cursor is at position 12 and Kenji inserts a letter at position 3, Hana’s cursor is now at 13. The server and the browsers shift cursors with the same rule they use for letters, which the first deep dive works out.
For past versions, the server finds the newest snapshot before the moment asked for and replays the edits from there to that moment. Restoring an old version is not rewinding the log. It is a new edit that changes the current text back to the old one, merged like any other, so nobody’s later edits vanish without a record.
The interactive version of this example is available when JavaScript loads.
On a quiet day this already works. The deep dives take it through six moments: two people typing into the same gap, a laptop that comes back from a long time offline, a reply that never arrives, a server that pauses and comes back, a document with two million edits, and an all-hands meeting of 2,000 people.
Two people type into the same gap. Whose letter comes first?
At 10:02 Hana and Kenji both edit the launch plan’s first line. To keep the letters simple, say the line reads ABCD. Hana types X between B and C. Kenji, before her X reaches him, types Y into the same gap. Each of them already sees their own letter: Hana sees ABXCD, and Kenji sees ABYCD. Now each edit travels to the other person.
The first answer is to save the whole text. Each browser sends its copy of the line, and the server keeps the last one it receives. Kenji’s arrives second, so the server keeps ABYCD and sends it to Hana. Her X is gone, and nothing told her. Locking avoids that: while Hana types in a paragraph, nobody else may. Google’s Docs team described this option and set it aside: “you could lock paragraphs so that only one editor was ever allowed to type in a single paragraph at a given time. But locking paragraphs isn’t a great solution” (Google). But two people fixing the same sentence at once is what a shared document is for.
The second answer is to send only the change. Hana’s browser sends “insert X at position 2”, counting positions from 0 so that position 2 is the gap between B and C. Kenji’s sends “insert Y at position 2”. Play it on each screen. Kenji’s screen shows ABYCD, and inserting X at position 2 gives ABXYCD. Hana’s screen shows ABXCD, and inserting Y at position 2 gives ABYXCD. The screens now disagree, and they will keep disagreeing, because every later edit is aimed at a different text on each.
The edits themselves were right. The positions were wrong by the time they arrived. Position 2 was counted on ABCD, and on Hana’s screen the text had already changed under it.
So rewrite each arriving edit to account for the edit that got there first. On Hana’s screen X already sits in the gap, so Kenji’s Y has to go one place further along, to position 3. That gives ABXYCD. On Kenji’s screen X is inserted at position 2, in front of his Y, which gives ABXYCD too. Both screens agree.
Something decided that X goes before Y. Two letters typed into the same gap at the same moment have no natural order, so every copy needs the same rule for a tie. Here, the server that numbers each document’s edits decides: the edit that reached it first goes first. Hana’s did.
Try two more situations. On the line ABCDE, Kenji deletes C while Hana types X between D and E. Her X was sent as position 4. On Kenji’s screen C is gone, so position 4 is now after E, and X belongs at position 3. On the line ABCD, both delete the same C. Without a rewrite, each browser deletes C, then applies the other’s “delete at position 2”, which now points at D. Both screens agree on AB, and both are wrong. Rewritten, the second delete finds its letter already gone and does nothing.
All three follow one rule. An edit moves forward one place for each letter inserted in front of it, and back one place for each letter deleted in front of it. Two inserts into the same gap need the tie rule. A delete of a letter that is already gone becomes nothing. This rewriting is operational transformation, or OT.
The experiment plays the three situations three ways. The tabs are saving the whole text, sending positions as they are, and transforming through the server.
The interactive version of this example is available when JavaScript loads.
In every situation the two screens end on the same text, whichever edit each saw first. Call that the first property: transforming Kenji’s edit past Hana’s, and Hana’s past Kenji’s, gives the same result. The tests behind the experiment check it for every pair of single-letter edits on short lines. With two people, it is all that is needed.
Three people are harder, if nobody is in charge. Add Luis. Without a server, Kenji might receive Hana’s edit and then Luis’s, while Luis receives Kenji’s and then Hana’s. Each copy transforms the same edits along a different path, and the rule now has to hold along every path, not just two. That second property is much harder, and the history of OT is full of algorithms that got it wrong. The first one, by Ellis and Gibbs in 1989, had “correctness issues” found years later (Wikipedia). The author of CodeMirror’s collaborative editing describes “an amusingly long list of papers in this space that have later been proven to be incorrect” (Haverbeke).
The fix is to put one server in charge of each document. It puts every edit into one order and numbers them: revision 41, 42, 43. Each browser then only ever reconciles with one other party, the server. Two parties need only the first property. The Jupiter system showed this in 1995: its “centralized architecture allows us to substantially simplify” the earlier algorithm (Nichols et al.). Google Docs uses Jupiter’s approach (Gentle and Kleppmann).
Walk the two edits through that server. Both were typed against revision 40. Hana’s X reaches the server first. It is the next edit, so it becomes revision 41. The server sends it to Kenji and tells Hana it is saved. Then Kenji’s Y arrives, still labelled “typed against revision 40”. The server has one edit since then, revision 41, so it transforms Y past X. Y moves to position 3, becomes revision 42, and goes to Hana.
Kenji’s browser does the mirror image. When X arrives, his own Y is still waiting for its answer. So the browser transforms X past Y. The server’s edit wins the tie, so X stays at position 2. Both screens show ABXYCD, and the server’s log holds X at 41 and Y at 42.
One question is left. What if Hana keeps typing while X is still waiting for its answer? If her browser sent every keystroke at once, each would be typed against a revision the server has not assigned yet. Google’s answer is to hold them back: “we never send more than one pending change at a time” (Google). Keys typed while one edit is in flight wait in a buffer. When the answer arrives, they go together as the next message, typed against the revision the answer named. So the server always knows what each message was typed against, and keys typed during a slow answer travel as one message.
The gap: Two edits typed at the same moment were each aimed at a text the other has already changed.
Option 1: Save the whole text
Each browser sends its whole copy, and the last one to arrive is kept.
Works when: Only one person edits at a time, as in a form.
Breaks when: One person’s edit silently replaces the other’s: Hana’s X is gone.
Option 2: Lock a paragraph
One person at a time may type in a paragraph.
Works when: Edits rarely touch the same paragraph, and waiting is acceptable.
Breaks when: Two people fixing one sentence must take turns, which is what the product exists to avoid.
Option 3: Transform through one server (start here)
Each edit carries the revision it was typed against; the server orders edits and moves a late one past those it missed, and browsers do the same for their pending edits.
Works when: Any product with a server that sees every edit, which is almost every one.
Watch for: The server must keep the edits a late browser missed, and one document cannot outgrow one server, which the last deep dive meets.
Option 4: A CRDT
Every letter carries a permanent ID, so edits merge in any order with no server.
Works when: Edits must merge without a server: peer to peer, or several regions accepting writes.
Watch for: Every letter carries an ID and deleted letters stay as markers, so a document takes much more memory; the next deep dive weighs it.
In the interview: Open with the ABCD example and play the positions as sent, so the interviewer sees two screens disagree with nothing failing. Then transform, and give the tie rule. When they ask about three people, say why one server per document is what makes the transform safe. Mention the one edit in flight before they ask how pending edits are tracked.
Say this: Two people type into the same gap, and each edit’s position was counted on a text the other has since changed. Applied as sent, the edits leave two screens that never agree again. Each document has one server that numbers every edit, and an edit carries the revision it was typed against. The server transforms a late edit past the ones it missed, and each browser transforms incoming edits past its own pending ones. Ties go to the edit the server took first. A browser keeps one edit in flight, and keys typed meanwhile go in the next message.
Kenji edits on a train for an hour. What happens when he reconnects?
At 18:00 Kenji’s train enters a long stretch with no signal. He keeps working on the launch plan: in the next hour he makes 300 edits. In the same hour Hana and three colleagues make 3,000. His last edit before the tunnel was revision 5,000, so when he reconnects at 19:00 the server is at revision 8,000 and has never seen his 300.
The first answer is to stop him editing: when the connection drops, the document turns read-only. That is honest, and it suits a phone on a flaky connection for a few seconds. For an hour on a train it throws away the reason he opened the document.
The second answer is the one the last deep dive built. Kenji’s browser sends his pending edits, all typed against revision 5,000. The server has 3,000 edits since then, so it transforms each of his 300 edits past each of those: 300 × 3,000 = 900,000 transforms. A transform of one letter past another takes about a microsecond, so that is under a second. His browser does the mirror image, moving the 3,000 incoming edits past his 300. Then both copies agree, and his hour of work is merged. Figma’s editor does something similar: “the client downloads a fresh copy of the document, reapplies any offline edits on top of this latest state” (Figma).
This way of catching up is called rebasing. Its cost is a product: the edits on one side times the edits on the other. An hour apart it is small. Two copies that drifted apart for weeks, each with tens of thousands of edits, can take far longer. Gentle and Kleppmann show that if two copies each make n edits since they last agreed, “merging their states using OT has a cost of at least O(n²)”. They tested a peer-to-peer OT algorithm on editing histories taken from Git projects with many long-lived branches. It took 6 seconds on one and an hour on another (Gentle and Kleppmann). And the server has to keep every edit since revision 5,000, for as long as a laptop might come back from being offline. The long-document deep dive puts a limit on that.
There is a different answer, which needs no server at all. Give every letter a permanent identity instead of a position, so an edit can say where it goes without counting. Then two copies can merge in any order, with nobody in charge. This is a CRDT, a conflict-free replicated data type.
The obvious way to give letters identities is a number line. Say A sits at 1 and B at 2. A letter typed between them takes the midpoint, 1.5. The next letter typed after it takes the midpoint of 1.5 and 2, which is 1.75. Sorting by number puts every letter in its place, whichever copy it arrived on first.
Play it with two words. Hana types “cat” between A and B, and Kenji types “dog” into the same gap, at the same time. Hana’s letters get 1.5, 1.75 and 1.875. Kenji’s, chosen the same way on his own copy, get the same three numbers. A tie is broken by who typed it, Hana first. Sorted, the line reads AcdaotgB. Both copies agree, and neither word survives. Kleppmann and colleagues found this problem in two published designs, Logoot and LSEQ. Text typed at the same spot “may be randomly interleaved on a character-by-character basis, resulting in an unreadable jumble of letters”, and their example ends as “Hello Al Ciharcliee!” (Kleppmann et al.).
The fix is to make each letter name the letter to its left. Kenji’s d says “after A”, his o says “after d”, and his g says “after o”. Hana’s letters do the same, starting from A. Each word is now a chain hanging off A, and sorting cannot pull a chain apart.
Two chains still hang off the same letter, so every copy needs a tie rule, as in the first deep dive. Give each letter an ID: a counter one higher than any the typist’s copy has seen, and a letter for who typed it. A and B were 1 and 2, so Kenji’s d is 3k and Hana’s c is 3h. The rule puts the chain with the larger ID first, and at equal counters k beats h. Which person wins does not matter; that every copy picks the same one does. Both copies read AdogcatB, and each word stays in one piece.
That keeps a word typed left to right together. The later Fugue paper found that the problem “affects both CRDTs and Operational Transformation”, in less common editing patterns. It proposed an ordering that avoids it (Weidner and Kleppmann).
Naming a neighbour creates the next problem. Say the line reads ABC. Kenji deletes B at the moment Hana types X after it. Hana’s X says “after B”. If Kenji’s copy erases B before X arrives, there is no B to put X after, and X can never appear on his screen. So a deleted letter is not erased. It stays in the document as a hidden marker, called a tombstone, so later edits can still find it. In the experiment, the hidden B lets X land between A and C on both copies.
Every letter ever typed keeps its ID, and every deleted letter keeps its place as a tombstone. That is why a CRDT costs memory. Careful libraries keep that cost far lower than early ones did: the Yjs library, for one, stores a document’s deletions compactly. The cost does not go away. Gentle and Kleppmann found in 2024 that “even the best CRDTs available today use more than 10 times as much memory as OT to view and edit a document”. That is why, in their words, “popular apps like Google Docs”, Microsoft Office and Overleaf use OT. A tombstone can only be dropped once every copy has seen the delete, and a laptop in a drawer may not have.
A server that sees every edit makes OT simple and cheap. This design already needs that server: it says Saved, checks access and sends edits on. A CRDT is the tool when edits must merge with no server in the middle: two laptops syncing directly, an app that works fully offline, or several regions that each accept writes. Yjs updates are “commutative, associative, and idempotent”, so they can be applied “in any order and multiple times” (Yjs).
The experiment merges two copies of one line with no server to order the edits. Its tabs are numbered positions, IDs that name the letter to the left with deleted letters erased, and the same IDs with deleted letters kept as hidden markers.
The interactive version of this example is available when JavaScript loads.
The gap: An offline laptop’s edits were typed against a revision the server has long moved past.
Option 1: Read-only while offline
The document stops accepting edits when the connection drops.
Works when: Blips of a few seconds on a phone.
Breaks when: An hour on a train is an hour of work refused.
Option 2: Rebase through the server (start here)
The browser sends its pending edits with their old revision, and the server transforms them past everything since.
Works when: A server sees every edit, and offline stretches last hours or days.
Watch for: Cost grows as the product of both sides’ edits, and the server must keep every edit a laptop might need; the long-document deep dive sets that limit.
Option 3: A CRDT such as Yjs or Automerge
Every letter has a permanent ID and names its left neighbour, and deleted letters stay as markers, so copies merge in any order.
Works when: Edits must merge without a server: peer to peer, fully offline, or several regions accepting writes.
Watch for: Memory: IDs on every letter and markers for every deletion, more than 10 times OT’s, and markers can only be dropped once every copy has seen the delete.
In the interview: Say what the server is already doing and why that makes rebasing cheap: 300 edits past 3,000 is under a second. Then give the CRDT its due: it merges in any order, and name when that matters. Show the interleaving problem with two words if the interviewer knows CRDTs, and the tombstone if they ask about deletes.
Say this: Kenji’s 300 edits were typed against revision 5,000, and the server is at 8,000. So the server transforms each of his edits past the 3,000 he missed: 900,000 small steps, under a second. The cost grows with both sides, and the server must keep old edits for as long as a laptop may be away, so that limit is a product decision. A CRDT gives every letter an ID so copies merge with no server, but it pays in memory for IDs and deleted markers. I would use one if edits had to merge peer to peer or in several regions at once.
The reply never came. Is Hana’s edit saved?
At 10:15 Hana types an exclamation mark after the heading. The document reads “Plan” at revision 82. Her browser sends edit h:7, typed against revision 82. The server writes it as revision 83. Then her office Wi-Fi drops, and the server’s answer never reaches her. Her screen shows “Plan!” and a label that says Saving. Is it saved?
Start with the fastest server. It answers “saved” the moment the edit arrives, then writes it to the log. Replay it with a crash in between. At 0.01 seconds Hana sees Saved. At 0.02 seconds the server crashes, before its write. The log never held the exclamation mark, so when she reloads, the document reads “Plan”, although she was told Saved.
So the server writes first and answers second. The edit goes into the log, the database confirms it, and only then does Hana’s browser hear “saved as revision 83”. This costs the time of one database write, a few milliseconds. Hana never feels it, because her letter was on the screen before the edit left her laptop. Only the Saved label waits. Written here means committed in PostgreSQL with a copy on a second machine. One machine failing then loses nothing.
That fixes the crash and leaves the lost reply. The server wrote revision 83, and the answer vanished on the way. Hana’s browser cannot tell that from an edit that never arrived. After 2 seconds with no answer, it has to send the edit again. If it sends it as a new edit, the server writes another exclamation mark as revision 84, and the document reads “Plan!!”. Every reader after her sees two.
The fix is to send the same edit again, not a new one. Every edit carries the browser’s client ID and its own sequence number, h:7. The log has a unique key on the document, the client ID and the sequence number. When the resend arrives, the server looks for h:7 first. It is already there as revision 83, so the server sends the same answer again, “h:7 is revision 83”, and writes nothing. The resend carries its old revision, 82, and that no longer matters: the server checks for h:7 before it transforms anything. Idempotency covers the general pattern.
The one edit in flight from the first deep dive makes this simple. The browser only ever has one unanswered edit, so after a reconnect it knows what to resend and under which number. The catch-up after a reconnect can also contain Hana’s own edit, revision 83. Her browser sees h:7 in it and takes it as the answer, instead of applying the exclamation mark a second time.
One more place can lose work: Hana’s laptop. If she closes the tab while an edit waits for its answer, and the browser only held it in memory, it is gone. So the browser writes each pending edit to its own storage, IndexedDB, as soon as it is typed, with its client ID and sequence number. A reopened tab then resends h:7 as h:7, not as a new edit. That gives three honest labels. Typed means only on the screen. Saved on this device means it survives closing the tab. Saved means written on the server. Only the server’s answer turns the second label into the third. A browser’s storage can be cleared by its owner or by the browser itself, so it never counts as the server.
The experiment sends Hana’s edit under three rules. The tabs are answering before the write, writing first and resending as a new edit, and writing first and resending the same ID.
The interactive version of this example is available when JavaScript loads.
The gap: A lost answer and a lost edit look the same to the browser.
Option 1: Answer, then write
The server says saved as soon as the edit arrives, then writes it.
Works when: Scratch notes, where losing the last few keystrokes in a crash is acceptable.
Breaks when: A crash between the two leaves a Saved label on an edit the log never held.
Option 2: Write, then answer; resend as new
The server answers after the write, and the browser resends an unanswered edit as a fresh one.
Works when: Edits where doing them twice changes nothing.
Breaks when: A lost answer turns one exclamation mark into two.
Option 3: Write, then answer; resend the same ID (start here)
Every edit carries a client ID and sequence number with a unique key in the log, so a resend gets the first answer back.
Works when: Every editor: this is the design.
Watch for: The log keeps a unique index on client and sequence, and the browser must store pending edits before it calls them saved on this device.
In the interview: Draw the reply getting lost after the write, and ask what the browser should do. Say “write first, then answer” and “resend under the same ID” as two separate fixes for two separate failures. Name the three labels, typed, saved on this device and saved, before the interviewer asks what Saved means.
Say this: Saved means the edit is in the log, so the server writes before it answers, and the letter was already on screen so nobody waits for it. A lost answer looks like a lost edit, so the browser resends. Every edit carries a client ID and sequence number with a unique key, so the resend gets the first answer back instead of a second copy. The browser also keeps pending edits in its own storage, and says saved on this device until the server answers.
The document’s server stops. Who owns the document now?
Doc 57, a design review, is owned by server A and reads ABCD at revision 80. Every edit to it has to go through one server, because that server is what puts the edits in one order. Now the fleet changes under it.
In step 2 each gateway picked the owner by hashing the document ID over its list of document servers. Consistent hashing keeps that cheap: adding a server moves only a small share of documents (consistent hashing). At 14:00 server B joins, and doc 57 is one of the documents that move to it. Gateways learn about B one at a time. For a moment Hana’s gateway still sends doc 57 to A, while Kenji’s already sends it to B. Hana types X at the end of the line, and Kenji types Y at the end too. A gives X revision 81, and B, which loaded the document at revision 80, gives Y revision 81 too. The log is a plain table with one row per edit, so it now holds two rows that both claim revision 81. Kenji was told his Y was saved, and anyone who opens the document gets one row or the other.
So ownership has to be decided in one place. A directory, usually etcd or ZooKeeper, records which server owns each document. Gateways ask it and cache the answer. A server holds one lease with the directory: a claim that expires after 10 seconds. The server renews it every 3 seconds, so a live server keeps it, and it owns its documents only while its lease holds. One lease per server, not per document, keeps the directory’s work small. If a server dies, its lease expires, and the directory gives its documents to other servers. B joining no longer splits doc 57, because every gateway asks the same directory, and the directory says A. Such a directory keeps several copies of its records and agrees on them with a consensus protocol, Raft in the case of etcd.
Now change the failure. Server A does not die. It pauses for 30 seconds: a long garbage-collection pause, a virtual machine moved to another host, a disk that stops answering. At 10 seconds its lease expires. At 11 seconds the directory gives doc 57 to B. B loads the snapshot and the log up to revision 80, and at 12 seconds writes Kenji’s Y as revision 81.
At 30 seconds A wakes up. From A’s point of view no time has passed. It was halfway through handling Hana’s X, and it still believes it owns doc 57. It writes X as a second revision 81. The lease worked as designed. A server that does not know its lease has ended keeps acting on it.
Look at what every owner does: it writes the next revision number. So let each revision be written only once. Make the document and the revision the log’s primary key. An append is then an insert that fails if that revision already exists. Replay the pause. At 30 seconds A tries to insert revision 81 for doc 57. Revision 81 is already there, B’s, so the insert fails. That failure is how A learns it no longer owns doc 57. It drops the document and closes its connections to the document’s editors. A never told Hana her X was saved, because it answers only after a successful write.
Hana’s browser reconnects. The gateway asks the directory, which now says B. Her browser says it has revision 80 and resends X, typed against 80. B sends her revision 81, Kenji’s Y. Her browser transforms its pending X past it, and B transforms X past Y and writes it as revision 82. Kenji’s Y was written first, so it wins the tie. Both screens show ABCDYX.
The same rule covers the race at the handover. If A slips revision 81 into the log before B finishes loading, B loads it and carries on from 81. If A slips it in after B has loaded but before B writes, B’s own insert of 81 fails, and B reloads and tries 82. Either way there is exactly one revision 81, and nobody who was told Saved loses an edit. The revision number that orders the edits also keeps a stale owner out. A check like this is called a fence.
A should not wait for the log to tell it, either. It also watches its own clock and stops serving a document a little before its lease would expire, allowing for clocks that drift. That keeps it from sending stale text and cursors to its editors. The log is what still holds when that clock check is wrong, as after a pause the server could not see.
The interactive version of this example is available when JavaScript loads.
The experiment plays two fleet changes three ways. The tabs are gateways that hash on their own, a directory with leases, and leases plus appends that check the revision.
The interactive version of this example is available when JavaScript loads.
The gap: Every edit to a document must go through one server, and the fleet changes under it.
Option 1: Each gateway hashes
Gateways hash the document ID over their own list of servers.
Works when: A fleet that never changes.
Breaks when: Gateways learn about a new server at different moments, and for that moment one document has two owners.
Option 2: A directory with leases
One directory grants each document to one server with a lease that must be renewed.
Works when: Servers that are either running or dead.
Breaks when: A server that pauses past its lease wakes up still believing it owns the document and writes a second revision beside the new owner’s.
Option 3: Leases, and appends that check the revision (start here)
The directory routes; the log accepts revision 81 only once, so a stale owner’s write fails and tells it to stop.
Works when: Every editor: this is the design.
Watch for: A server that loses a race must drop the document and its connections at once, and its editors reconnect and resend.
In the interview: Start with how a gateway finds a document’s server, then add a server and let the interviewer watch two owners appear. Bring in the directory and the lease, then pause a server and ask what it does when it wakes. The answer they want is that the store must refuse the stale write.
Say this: Every edit to a document goes through one server. A directory like etcd records which server owns each document, each server holds a lease, and gateways ask the directory where to send edits. A lease cannot stop a server that paused and does not know it expired. So the log refuses a second write of any revision number: its key is the document and the revision. The stale owner’s insert fails, it drops the document, and its editors reconnect to the new owner and resend.
A three-year-old document takes 40 seconds to open. Why?
The team handbook has been edited 2,000 times a day for 1,000 days: 2,000 × 1,000 = 2,000,000 edits. Step 2 said the document server writes a snapshot “every so often”. How often, and what else it keeps, decides how fast this document opens and how far back its history reaches.
Start with no snapshots at all, and rebuild the document from its log. Google described Docs this way in 2010: “To display a document, we replay the revision log from the beginning” (Google). Say applying one edit takes 20 microseconds. Then opening the handbook means 2,000,000 × 20 µs = 40 seconds before the first letter appears.
The first answer is to keep only the latest text. When an edit is written, fold it into the stored text and forget it. Opening becomes instant, with nothing to replay.
Then two things break. Hana asks for last Tuesday’s version, at 16:20, and there is none. The only text is today’s. And Kenji’s laptop comes back after 5 days offline with 12 pending edits typed against revision 1,990,000. Those edits say where to insert in revision 1,990,000, and the server no longer knows what revision 1,990,000 looked like, so it cannot transform them. The log is what makes history and late edits possible.
So keep the log and add snapshots. Every 1,000 edits, the document’s server writes the whole text, with the revision it belongs to, to object storage. Opening loads the newest snapshot and replays the edits after it, at most 999. That is 999 × 20 µs, about 20 milliseconds.
Past versions work the same way. Tuesday at 16:20 was revision 1,986,420. The server loads the snapshot at 1,986,000 and replays 420 edits, 8.4 milliseconds. Kenji’s laptop still works too. The log has all 10,000 edits since his revision 1,990,000, so the server transforms his 12 edits past them: 12 × 10,000 = 120,000 small steps.
Snapshots make opening fast, and the log still grows forever. Work it out for the whole fleet. A million edits a second, at about 100 bytes each, is 1,000,000 × 100 × 86,400 = 8.64 terabytes a day. That is the busiest hour’s rate held all day, so it is a ceiling, and the second copy of every write doubles it.
So set a horizon. Keep every edit for the last 30 days, which is at most 30 × 8.64 = 259.2 terabytes for the fleet, before the second copy. For anything older, a compactor keeps one snapshot a day and deletes the edits between them. Version history still reaches back years, a day at a time, and the last month keystroke by keystroke.
Kenji’s laptop comes back after 40 days. Its edits were typed against revision 1,920,000, and the edits after it have been folded into daily snapshots. The server no longer has the list of changes his 12 edits would need to be moved past. His browser still has the text his edits were typed on. So his browser can fetch today’s text and compare three texts, that old one, his and today’s, the way a code merge does. That is a guess at what he meant, and it can conflict. So his browser keeps the result as a separate copy of the document and tells him, and he checks it by hand. File sync apps make the same choice when they save a conflicted copy, as the file storage breakdown explains. A compactor could instead keep one combined edit per day, so a late laptop is transformed past 40 of them. That reaches further back and stores more. Any system that keeps less than everything has a limit like this. This one is decided in advance and written down.
A CRDT would face the same choice with a different cost. Its snapshot must keep every letter’s ID and every hidden marker, or a laptop that comes back later cannot merge. Yjs states the choice: “Set doc.gc = false to disable garbage collection and be able to restore old content” (Yjs).
The interactive version of this example is available when JavaScript loads.
The experiment asks four questions of the handbook three ways. The tabs are replaying the whole log, keeping only the latest text, and snapshots with 30 days of edits.
The interactive version of this example is available when JavaScript loads.
The gap: The log is what makes history and late edits work, and it grows without limit.
Option 1: Replay the whole log
Every open rebuilds the text from the first edit.
Works when: Short-lived documents with a few thousand edits.
Breaks when: The handbook takes 40 seconds to open, and it gets slower every day.
Option 2: Keep only the latest text
Each edit is folded into the text and forgotten.
Works when: Documents with no history and no offline editing.
Breaks when: Last Tuesday’s version is gone, and a laptop’s late edits cannot be transformed.
Option 3: Snapshots, and 30 days of edits (start here)
A snapshot every 1,000 edits for opening, every edit for 30 days, and one snapshot a day before that.
Works when: Every editor with history and offline editing.
Watch for: A laptop offline for longer than 30 days is merged by comparing texts and kept as a separate copy to check, which is a stated limit.
In the interview: Work out the 40 seconds before proposing anything, so the snapshot is the answer to a number. Then ask what the log is for, and answer with history and the late laptop. Name the horizon as a product decision, and say what happens to a laptop past it.
Say this: Replaying two million edits at 20 microseconds each takes 40 seconds. So the server writes a snapshot every 1,000 edits and opens from the newest one plus at most 999 edits, about 20 milliseconds. The log is still needed for history and for transforming a laptop’s late edits, but it grows by up to about 8.6 terabytes a day fleet-wide, before the second copy. So every edit is kept for 30 days and older ones are folded into daily snapshots. A laptop offline longer than that gets its edits kept as a separate copy.
Two thousand people open the all-hands notes. What breaks first?
At 17:00 the whole company joins the all-hands meeting, and 2,000 people open the meeting notes. Forty of them type: the host, the note-takers, people adding questions. Everyone else watches the text and the cursors move.
Say each typist presses 5 keys a second, steadily. Each answer comes back well within the 200 ms between keys, so every key travels as its own message. Follow one keystroke. It changes the text and moves the typist’s cursor, so the server sends two messages, the edit and the cursor, to each of the other 1,999 people. Forty people typing 5 keys a second make 40 × 5 × 1,999 × 2 = 799,600 messages a second, for one document. Say one document may use 20,000 messages a second of its server’s capacity. This is forty times that. The server falls behind, the queue for every connection grows, and the typists see their colleagues’ letters arrive seconds late.
The first fix is batching. Instead of sending each change the moment it happens, the server collects every change for 50 milliseconds and sends each person one message with all of them. The message carries each cursor’s latest position only. A cursor that moved ten times in 50 milliseconds is sent once, where it ended. Now each person gets 20 messages a second whatever the typing rate. With 2,000 people that is 2,000 × 20 = 40,000 messages a second. That is twenty times better and still twice the budget. And 39,200 of those messages go to people who are only watching.
So stop the document’s server from talking to the watchers at all. The 40 editors still get a batch every 50 ms from the server: 800 messages a second. The watchers connect to relays instead. Say 20 of them, about 98 watchers each. The server sends each relay the same batches it sends an editor, 20 × 20 = 400 a second. Each relay sends its watchers a batch every 250 ms, because someone who is only reading does not notice a quarter of a second. The server now sends 800 + 400 = 1,200 messages a second, and the relays share the other 1,960 × 4 = 7,840. A relay never orders anything. It is a copying tree, like a CDN for live edits.
Relays do not help the editing side. Every edit to one document goes through one server, because that is what puts the edits in one order. So the number of people typing in one document has a ceiling. Google Docs caps everyone at once: “You can let up to 100 people with view, edit, or comment permissions work on a Google Docs, Sheets, or Slides file at the same time.” Past that, “only the owner and some users with editing permissions can edit the file”. For a larger audience, its advice is to “publish it as a web page instead” (Google). Interviewers sometimes push to a million people viewing one document. The answer is a deeper relay tree, or a published copy refreshed every few seconds and served through a CDN, with the editors still capped.
Cursors deserve their own rules. They are half of these messages and none of the record. The browser sends its cursor at most 10 times a second. Liveblocks, a collaboration service, throttles each client’s messages to “one every 100 milliseconds” by default (Liveblocks). The server keeps only each person’s latest cursor, drops older ones when it falls behind, and removes a cursor whose browser goes quiet. Yjs marks a person offline after 30 seconds without an update (Yjs). When the server is overloaded, cursors get jumpy before edits get late.
The interactive version of this example is available when JavaScript loads.
The experiment sends one document’s changes three ways, for an all-hands and for a team document. The tabs are every keystroke to everyone, one batch per person every 50 ms, and batches with relays for watchers.
The interactive version of this example is available when JavaScript loads.
The gap: Every change goes to everyone in the document, so traffic grows with typists times readers.
Option 1: Every keystroke to everyone
Each edit and each cursor move is sent to every other person at once.
Works when: Team documents: 8 typing and 12 watching cost 1,520 messages a second.
Breaks when: An all-hands of 2,000 costs 799,600 a second, forty times the budget.
Option 2: One batch per person every 50 ms
Changes are collected for 50 ms and sent as one message, with each cursor’s latest position only.
Works when: Documents of a few hundred people.
Breaks when: At 2,000 people it is still 40,000 a second, most of it to people only watching.
Option 3: Batches, and relays for watchers (start here)
Editors get batches from the server; watchers get coarser batches from relays that copy and never order.
Works when: Large audiences, with editors capped.
Watch for: Watchers see changes up to 250 ms later. Editors per document stay limited, because one server orders every edit.
In the interview: Work out the 799,600 before proposing anything. Batch first and show it is still not enough, then separate editors from watchers. Say that relays scale the audience and not the editors, and give the cap as a product decision, with Google’s 100 people per file as a real example.
Say this: One keystroke goes to every other person twice, as the letter and the moved cursor. So 40 typists with 2,000 readers is about 800,000 messages a second for one document. Batching every 50 ms, with only each cursor’s latest position, brings it to 40,000. Moving the watchers onto relays that copy the batches brings the document’s server down to 1,200. Relays scale the audience, not the editors, because one server still orders every edit. So a document caps how many people it serves live, as Google Docs caps a file at 100 people and sends bigger audiences to a published copy.
The interactive version of this example is available when JavaScript loads.
The code has three tabs: the transform for single letters, the server taking an edit, and the browser that keeps one edit in flight.
If they ask: bold at the edge of a word
Formatting is an edit like any other, with a range instead of a position. Google described Docs’ edits as “inserting text, deleting text, and applying styles to a range of text”. A style range grows when text is inserted inside it. Its example: “{ApplyStyle bold @10-20} transformed against {InsertText ‘ABC’ @15} results in {ApplyStyle Bold @10-23}” (Google).
The hard case is text typed at the edge of a bold word, where the editor must decide whether the new letter is bold. Editors agree on a rule: text typed before a bold span is not bold, and text typed after it is. Ink & Switch tested “Microsoft Word, Google Docs, Apple Pages” and found that “the text inserted before the bold span becomes non-bold, and the text inserted after the bold span becomes bold” (Peritext). Links are the exception, because a link that grows as you type is a surprise. Say the rule out loud, and say that it lives in the transform.
If they ask: undo in a shared document
Hana presses undo. She expects her last edit to disappear, not Kenji’s, even though his came after hers. So undo is never “go back one revision”. The browser keeps a stack of Hana’s own edits. Undo builds the opposite of her last one, a delete for an insert, and transforms it past everything that happened since, the way a late edit is transformed. Then it sends that as a new edit. If Kenji has since deleted the word Hana typed, the transform turns her undo into nothing at all.
If they ask: someone loses access while offline
Kenji is on the train when Ruth, the document’s owner, removes his edit access. He keeps typing, because his laptop does not know. When he reconnects, the server checks his access before it takes a single edit, on every message, not only when the connection opened. It keeps the document’s access list in memory and refreshes it the moment sharing changes, so the check costs almost nothing. It refuses his pending edits with a clear reason. His browser keeps them as a separate copy on his laptop, so they are not silently destroyed, and they never reach the shared document. What he had already read, he keeps. No system can take back text a browser has already been sent.
If they ask: people in another region
The launch plan’s server is in Virginia, and a new colleague joins from Tokyo, about 11,000 km away. Light in fibre covers about 200 km a millisecond, so a round trip takes at least 2 × 11,000 ÷ 200 = 110 milliseconds. Her own letters still appear at once, because the browser never waits. Colleagues near Virginia see them at least 55 milliseconds later, the one-way trip, and she sees Saved at least 110 milliseconds after she types. One server still has to order the document, so the fix is placement. The directory can move a document’s ownership to the region where most of its editors are, using the same lease and fence as a failover. If Saved must survive losing the whole region, every write must also reach a second region before the answer. From Virginia to Oregon, about 3,700 km, that adds at least 2 × 3,700 ÷ 200 = 37 milliseconds to every Saved. Latency across distance works through these numbers.
If they ask: search across my documents
Search is a separate system fed by the same edits. An indexer reads new snapshots, or the log, and updates an inverted index of words to documents. Every search result is checked against the access table before it is shown, because a document someone lost access to yesterday must not appear in their results today. The post search breakdown designs that index.
Walk one keystroke through the final design
Hana opens the launch plan in the evening, when it is at revision 8,340. Her browser opens a WebSocket to a gateway. The gateway asks the directory who owns doc 42, and the directory says server A, whose lease is current. A loaded the document from the snapshot at revision 8,000 and the 340 edits after it.
Hana types X. Her browser shows it at once and writes it to its own storage as pending edit h:812, typed against revision 8,340. It is the only edit in flight, so it goes straight out. A checks that Hana may still edit, then looks for h:812 in the log. It is not there, and nothing has arrived since revision 8,340, so A inserts it as revision 8,341. The insert succeeds, because nobody else has written revision 8,341, so A still owns the document. A answers “h:812 is revision 8,341”, and Hana’s label turns to Saved.
A sends revision 8,341 to Kenji in the next 50-millisecond batch, with Hana’s cursor. Kenji’s browser has his own Y pending in the same gap, so it transforms X past Y, and X stays in front because the server took it first. The relays copy the same batch to the people watching. At the 1,000th edit since the last snapshot, A writes a new one, and in 30 days the compactor folds Hana’s X into a daily snapshot.
The interactive version of this example is available when JavaScript loads.
| Requirement | Where it is met | The trade-off |
|---|---|---|
| FR1: create and share | Document API, documents database, access checked on every edit | An access check on every message |
| FR2: edit together | One server per document orders and transforms edits | One document cannot outgrow one server |
| FR3: see each other | Cursors forwarded in batches and never stored | Cursors jump when the server is busy |
| FR4: keep typing offline | Pending edits on the device, rebased on reconnect | A 30-day horizon, then a separate copy |
| FR5: past versions | Snapshots and the edit log, daily snapshots after 30 days | Old history is kept a day at a time |
| Every copy ends the same | Transforms through one ordering server, and a fixed tie rule | The server must keep edits a late browser missed |
| Saved survives a crash | Write before answering, resend under the same ID, revision numbers written once | A database write on every message |
How does the answer change for a code editor, Notion or Figma?
| Interview variant | What carries over | What changes |
|---|---|---|
| Design Google Docs or Word for the web | Everything on this page | The same problem; ask about comments, suggestions and tables |
| Design a collaborative code editor | Transforms, one server per file, cursors | Plain text with no formatting, and running the code is a separate sandbox; the coding platform breakdown covers that |
| Design Notion or a block editor | Ordering, saving, ownership | A document is a tree of blocks with IDs, so moving a block is its own edit, and text merges inside each block |
| Design Figma multiplayer or a whiteboard | One server per document, cursors, relays | Objects with properties, not a sequence of letters; Figma keeps “the last value that was sent to the server” for each property |
| Design Google Sheets | The server, the log, snapshots | Each cell takes the last write, and inserting a row shifts every reference below it, which is a transform |
| Design an offline-first notes app | Pending edits, the horizon | No server in the middle is the point, so it is the CRDT answer |
What should an answer reach at each level?
| Level | What the answer shows |
|---|---|
| Intern or mid-level | Sends edits instead of whole documents over a WebSocket, keeps an edit log and snapshots, and routes a document’s editors to one server. Keeps cursors out of the log. |
| Senior | Walks the transform with revisions and the tie rule, keeps one edit in flight, writes before answering and dedupes resends by client and sequence. Handles reconnect by rebasing pending edits. |
| Staff | Explains why operational transformation needs one ordering server, when a CRDT fits and what its IDs and tombstones cost, and how the log’s revision numbers fence out a paused owner. Separates editors from watchers. |
| Principal | Decides the product limits and says them out loud: how many editors a document allows, how long offline edits can merge, what Saved promises across regions, and when the cost of a CRDT is worth paying. |
Test yourself with the quiz, then pick another problem from the System Design interview breakdowns.
By GOAT Engineer. Back to all breakdowns. Privacy Policy · Contact.