Let many people edit one document at the same time and always end up with the same text.
“Design a collaborative document editor like Google Docs.”
It is short on purpose. Your first job is to make it specific.
| What they check | Why it matters |
|---|---|
| Seeing the real problem | Sending edits is easy. Making every copy end up the same, while keeping what each person meant, is the whole question. A strong candidate says this in the first two minutes. |
| Convergence and intent | The interviewer wants a concrete example of two edits crossing, and a mechanism (OT or CRDT) that fixes it. “Last write wins” fails this test. |
| A single order per document | A central server that numbers every edit makes OT simple. Knowing why, and what it costs, shows depth. |
| Real-time delivery at scale | Millions of open sockets, one serialised writer per document, hot documents with thousands of viewers, and reconnects after a crash. |
| Durability and recovery | An edit that was acknowledged must never be lost. Log first, then acknowledge, then broadcast. Snapshots keep recovery short. |
Every document is owned by one session server at a time. Clients connect with WebSockets, apply their own edits at once (optimistic), and send each edit with the revision it was based on. The session server puts all edits into one order, rewrites a late edit against the edits it missed (operational transformation), writes it to an append-only log, then sends it to everyone.
| Step | Minutes | What to get done |
|---|---|---|
| 1. Clarify | 4 | Plain or rich text, how many editors, offline, how fast remote edits must appear, what history means. |
| 2. Estimate | 4 | Connections, edits per second, gateways, session servers, log growth and snapshots. |
| 3. API and data | 5 | The WebSocket messages (join, op, ack), the revision rule, and the log and snapshot tables. |
| 4. High-level design | 7 | Gateway, session server per document, log, snapshots, presence. Follow one edit. |
| 5. Deep dives | 15 | Convergence (OT), OT versus CRDT, delivery at scale, storage and recovery, offline and permissions. |
| 6. Scale and failures | 7 | Session server dies, gateway dies, hot document, a very long offline merge. |
| 7. Wrap up | 3 | Recap, the cost of one owner per document, and what you would build next. |
| Ask | Why you ask it | Typical answer | How it changes the design |
|---|---|---|---|
| Plain text, or rich text with formatting, tables and images? | Rich text needs more kinds of edits (format, split, merge) and more transform rules. Plain text keeps the core idea clear. | Start with plain text. Say that formatting is the same idea with more operation types. | We design the engine for insert and delete, and name formatting as an extension. |
| How many people edit one document at once, and how many just view? | Typical is 2 to 10. A few documents have thousands of viewers. The two cases need different tiers. | Up to 100 editors, usually 2 to 10. A few documents have 10,000 read-only viewers. | Editors share one session. Viewers are served through a separate fan-out tier. |
| How fast must a remote edit appear, and how fast must my own typing feel? | Your own typing must be instant, so it cannot wait for the server. That forces optimistic local apply. | Local edits instant. Remote edits visible within 200 to 500 ms. | Clients apply edits locally first, and the server must reconcile them afterwards. |
| Must it work offline, and merge when I come back? | Offline means long runs of edits that conflict with others. It strongly favours one design over another. | Yes, for a few hours or days, and merge on reconnect. | Edits queue on the client with ids, and rebase on reconnect. We compare OT and CRDT here. |
| Do we need version history and undo? | History decides whether we keep the full log. Undo in a shared document is its own problem. | Named versions and a restore, plus per-user undo. | An append-only log with snapshots. Undo is a new edit, not a rewind. |
| Who may do what: view, comment, edit? Can access be removed while the document is open? | Permissions must be checked on every edit, not only when the document opens. | Three roles. Removing access must stop a live session within seconds. | The session server checks the role on every edit and can close a socket. |
| How big can one document get? | Size sets snapshot size, load time and how much metadata per letter we can afford. | Up to about 1 MB of text, around a million characters. | A snapshot loads in one read. A CRDT with 20 bytes per letter would be 20 MB, which hurts. |
| Are comments, suggestions and cursors in scope? | Comments and cursors must move with the text, which makes them transform targets too. | Live cursors and presence yes. Comments as an extension. | Presence is ephemeral and transformed with edits. Comment anchors are left for later. |
| How many documents and users, and how many are open at the same moment? | Concurrently open documents and connections size the gateways and session servers. | 1B documents, 50M daily users, about 5M documents open at once. | About 10M connections, so 100 to 200 gateway servers. |
| One region or several? What happens if a region fails? | Cross-region editing of one document means either one owner region or a CRDT. | One region per document at a time, with failover to another. | No cross-region writes to the same document. Multi-region is an extension. |
| Assumption | Value |
|---|---|
| Documents stored | 1 billion |
| Daily users | 50 million |
| Documents open at the same moment | 5 million |
| Connections (editors and viewers) | 10 million, about 2 per open document |
| Share of connections actually typing | 10% |
| Edits per typing user, after batching | 1 a second at the busiest moments |
| Average over a day (versus the busiest moment) | 25% of the busiest rate |
| Edit message size | about 100 bytes |
| Average document | 50 KB of text (a snapshot) |
| One gateway | 100,000 connections |
| Session servers | 100, each owning many documents |
| What | Maths | Result |
|---|---|---|
| Busy-moment edits per second | 10,000,000 × 10% × 1 per second | 1,000,000 edits per second |
| Edit traffic into the system | 1,000,000 × 100 bytes | 100 MB per second |
| Messages out (each edit goes to about 2 other people) | 1,000,000 × 2 | 2,000,000 messages per second (200 MB per second) |
| Gateway servers | 10,000,000 ÷ 100,000, then × 2 for headroom | 100 minimum, so about 200 |
| Documents and edits per session server | 5,000,000 ÷ 100, and 1,000,000 ÷ 100 | 50,000 documents and 10,000 edits per second each |
| Memory per session server | 50,000 documents × (50 KB text + 10 KB recent edits) | about 3 GB (small) |
| Average edits per day | 1,000,000 × 25% × 86,400 | about 21.6 billion edits a day |
| Raw log per day | 21.6 billion × 100 bytes | about 2.2 TB a day (6.5 TB with 3 copies) |
| Log after merging bursts of typing (about 5 keystrokes into one edit) | 2.2 TB ÷ 5 | about 0.43 TB a day |
| Hot log for 30 days | 0.43 TB × 30, then × 3 copies | about 13 TB, 39 TB with copies |
| Snapshots of every document | 1,000,000,000 × 50 KB | 50 TB (75 TB with erasure coding, 150 TB with 3 copies) |
| Replay after a crash with a snapshot every 1,000 edits | 1,000 × 100 bytes | at most 100 KB per document |
| A session server dies: documents to reload | 50,000 documents ÷ 5,000 per second | about 10 seconds, and about 100,000 clients reconnecting |
| One hot document with 10,000 viewers and 10 edits a second | 10 × 10,000 | 100,000 messages per second from one server (the problem) |
| The same document with a fan-out tier (5 edge nodes of 2,000 viewers) | 10 × 5 | 50 messages per second from the session server |
| Method | Path | Request | Response | Notes |
|---|---|---|---|---|
| GET | /v1/docs/{id}/connect | upgrade to WebSocket | 101 Switching Protocols | The gateway checks the user's role and routes to the session server for this document (consistent hashing). Sticky: all editors of one document reach the same server. |
| WS | join | { docId, lastKnownRevision, clientId } | { revision, snapshot or edits since lastKnownRevision, collaborators } | A reconnect sends the last revision it saw and gets only the missing edits. A new client gets the latest snapshot plus the log tail. |
| WS | op | { opId, baseRevision, ops: [insert(pos, text) or delete(pos, len)] } | { ack: revision } to the sender, { op, revision } to everyone else | baseRevision is the revision the client had when it typed. opId makes a resend harmless (dedup). One edit in flight per client. |
| WS | presence | { cursor, selection } | broadcast to collaborators | Ephemeral and throttled (for example 5 a second). Never written to the log. Transformed with edits so a cursor stays on its letter. |
| GET | /v1/docs/{id}/history?from=&to= | none | 200 { versions, nextCursor } | Named versions and revision ranges. Reads the history store. Restore creates a new edit, it does not rewrite the log. |
| PUT | /v1/docs/{id}/permissions | { user, role } | 204 | Takes effect immediately: the session server drops the socket if the role is removed. Needs the owner role. |
| Table or store | Key | Holds |
|---|---|---|
| doc_meta (sharded SQL or KV) | doc_id | Title, owner, created time, current head revision, snapshot pointer, owner session server hint. |
| acl | doc_id, user_id | The role (view, comment, edit) and link-sharing settings. Cached at the gateway with a short TTL, checked again by the session server. |
| op_log (append-only, wide-column or log store) | doc_id, revision | One edit per row: opId, author, baseRevision, the transformed op, time. Never updated. |
| snapshots (object storage) | doc_id, revision | Full text at a revision. Written every 1,000 edits and at close. Used to load fast. |
| versions | doc_id, version_id | A name, a revision number and an author. A version is a pointer into the log, not a copy. |
on op(client, opId, baseRevision, ops):
if seen(opId): return ack(existing revision) # resend is harmless
for e in log[baseRevision+1 .. head]: # edits the client had not seen
ops = transform(ops, e.ops) # rewrite against each one, in order
head += 1
append(log, head, opId, ops) # durable BEFORE we answer
ack(client, head)
broadcast(everyone except client, ops, head)| Component | What it does |
|---|---|
| Client (editor engine) | Keeps the local text, one edit in flight and a buffer of the rest. Applies its own edit at once, then rewrites incoming edits against what it has pending. |
| Gateway | Terminates WebSockets, authenticates, checks the role, and forwards each connection to the session server that owns the document. |
| Session server | The single writer for a document. Numbers edits, rewrites late edits, appends to the log, acknowledges, and broadcasts. Holds the live text in memory. |
| Owner map (with epoch) | Says which session server owns a document, using consistent hashing and a lease. The epoch grows with each new owner, so an old owner can be fenced. |
| Operation log | Append-only record of every accepted edit. The source of truth. Replicated, and written before any acknowledgement. |
| Snapshot store | Full text at a revision, every 1,000 edits. Bounds recovery time and makes opening a document fast. |
| Presence service | Cursors and who is online. In memory only, throttled, and transformed with edits. Losing it loses nothing important. |
| Fan-out tier | Delivers each edit to thousands of read-only viewers of a hot document, so the session server sends a handful of messages, not thousands. |
The problem: Two people edit the same text at once. Each applies their own edit at once, then receives the other's. An edit is “insert at index 0” or “delete index 2”, but by the time it arrives, the text has already changed and the index now points at something else. Invariant: every copy ends with the same text, and each person's edit still means what they meant.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Lock the document or a paragraph | Only one person may edit a region at a time. Others wait or are blocked. | No conflicts at all. Simple to build. | Typing is not instant. People cannot work together, which defeats the product. |
| Last write wins (send the whole text) | Each save replaces the document with the sender's copy. The newest one wins. | Trivial. Always converges. | Destroys the other person's work. Fails the intent test completely. |
| Send raw edits by index | Send “insert X at 0” and apply it at that index on every copy. | Small messages, instant local apply. | Copies diverge or delete the wrong letter, because an index means different things on different copies. This is the bug that OT exists to fix. |
| Operational transformation with one server order | The server numbers edits. A later edit is rewritten against the edits it had not seen, so its index fits the current text. Clients do the same for incoming edits against their one pending edit. | Instant local typing, small messages, convergence, intent kept. Proven in large products. | Needs a central order. The transform rules are subtle and must be tested for every pair of edit types. |
The invariant is every replica applies the same edits in the same order after the same rewriting. The session server enforces the order with one revision counter. The rewriting follows a rule: for two concurrent edits A and B, applying A then B' gives the same text as applying B then A'. Because the server keeps one history, a late edit only needs rewriting against the edits after its base revision, not against everyone's.
The cost is a central writer per document and a transform function you must get right. We accept both: one writer per document is cheap (a document is only about 10 edits a second), and we test the transform with every pair of operations and random sequences.
| Pair of concurrent edits | How the later one is rewritten |
|---|---|
| insert vs insert | If the other insert is before mine, or at the same index and from a lower site id, my index goes up by 1. The tie-break must be the same everywhere. |
| insert vs delete | If the other delete is before my index, my index goes down by 1. |
| delete vs insert | If the other insert is at or before my index, my index goes up by 1. |
| delete vs delete | If it is the same letter, my edit becomes nothing (it is already gone). If before, my index goes down by 1. |
The problem: OT needs a central order and careful transform rules. A CRDT avoids both by making edits commute. Which do we choose, and what does each cost? This decides offline support, memory use and whether a central server is required at all.
| Option | How it works | Good | Bad |
|---|---|---|---|
| OT with a central server | One server per document orders edits and rewrites them. Clients keep one edit in flight. | Small metadata: the text is just text. Mature for rich text. Easy to enforce permissions on one server. | Needs the server to be reachable. Transform functions grow with each edit type. Long offline sessions mean a big rebase. |
| Sequence CRDT (RGA, Logoot, Yjs, Automerge style) | Every letter has a unique id, and an insert says “after letter with id N”. Deleted letters stay as tombstones. Edits commute, so any order gives the same text. | No transformation and no central order. Works peer to peer and offline. Merges are easy to reason about. | Metadata per letter (often 10 to 30 bytes), tombstones that need cleanup, and history that grows. A 1M-character document can use 20 MB or more. |
| Hybrid: CRDT for the data, server for everything else | Use a CRDT for the text, but still route through a server for permissions, ordering of snapshots and persistence. | Offline and merge strength of a CRDT, with a server for access control and storage. | Two sets of ideas to run and debug. The server cannot easily inspect or limit an edit. |
| Operation log with last-write-wins per field | Treat the document as a map of paragraphs and keep the newest write of each paragraph. | Simple and fits form-like data. | Two people typing in one paragraph overwrite each other. Not collaborative text editing. |
For a hosted editor with a server and permission checks, OT is a good fit: the document is plain text with no per-letter metadata, the server is already the one place that owns order, and large products such as Google Docs are known to use OT. A CRDT is the better answer when offline-first, peer-to-peer or no central server matters, and many newer editors use CRDTs for that reason.
The deciding trade-off is metadata against coordination. OT pays with a central writer and subtle transform code. A CRDT pays with memory and tombstones on every letter. Say both, pick one for this product, and say what would flip the choice.
| OT (server order) | Sequence CRDT | |
|---|---|---|
| Needs a central order | Yes, per document | No |
| Extra data per letter | None | An id, and a tombstone after deletion |
| 1M-character document | About 1 MB of text | Often 10 to 30 MB with ids and tombstones (illustrative) |
| Long offline edits | A large rebase against many edits | A merge of two sets of edits, usually easier |
| Hardest part | Getting every transform pair right | Cleaning up tombstones and long history |
Try the visualizer below: it runs the same two edits through raw sending, OT and CRDT-style ids, and shows which copies agree.
The problem: 10 million sockets, 1 million edits a second, and every edit must reach the right people in order. One busy document must stay on one writer. A hot document with 10,000 viewers would make one server send 100,000 messages a second. And every server crash drops thousands of connections at once.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Any server handles any edit (stateless) | Edits go to any app server, which reads and writes the document in a database with a lock or transaction. | Easy to scale and restart. | Every edit pays a database round trip and a lock. Latency and contention are high, and ordering is hard. |
| One owner session server per document (consistent hashing) | Route each document to a single server that keeps it in memory and orders its edits. | Ordering is a local counter. No distributed transaction. Memory is fast. | A failed owner pauses its documents until another takes over. Hot documents must be handled separately. |
| Pub/sub between servers with a per-document topic | Any server accepts edits and publishes them to a topic. Subscribers apply them. | Easy fan-out. Decouples servers. | Needs a single order for the topic anyway. Adds a hop of latency to every edit. |
| Owner session for editors + fan-out tier for viewers | Editors stay in the owner session. Read-only viewers connect to edge nodes that subscribe to the document and relay edits. | The owner sends a handful of messages, not thousands. Viewers scale horizontally. | Viewers lag by a hop. A second tier to run, and viewers who become editors must move. |
A document is tiny in write terms (about 10 edits a second even when busy), so putting all editors of one document on one server costs nothing and makes ordering trivial: a counter in memory. Consistent hashing on the document id gives routing and spreads documents evenly. This is the same trade as a single leader per partition: a short pause on failure, in exchange for no distributed coordination on the hot path.
For the rare hot document, the fan-out tier turns 100,000 messages a second from one server into 50 (5 edge nodes of 2,000 viewers each). Viewers need only the final text and the stream of edits, so they never join the transform logic.
| Concern | How we handle it |
|---|---|
| Reconnect after a drop | The client sends its last revision. The server replies with the edits since then, or a fresh snapshot if too much time has passed. A revision gap on the client triggers the same request. |
| Reconnect storm after a server dies | 100,000 clients return at once. Jittered retry with backoff on the client, a gateway rate limit, and snapshots in a cache so the load is on memory, not on the log. |
| Batching and compression | Merge a burst of keystrokes into one edit (about 5 to 1), and send at most a few messages a second per client. Compress frames. |
| Slow client | Never block the session on one slow socket. Buffer a bounded queue, and past the limit drop the socket and let it re-sync from a revision. |
| Presence and cursors | Ephemeral and throttled (about 5 a second). Kept in memory only, and transformed with edits so a cursor stays on its letter. |
The problem: An edit that was acknowledged must never be lost, even if the session server dies a millisecond later. The log grows forever, a recovery must be quick, and there is a nasty case: an old owner that was only paused wakes up and keeps accepting edits for a document another server now owns. Invariant: an acknowledged edit is in the replicated log, and only one owner appends at a time.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Keep the document in memory, save every few seconds | The session server holds the text and writes snapshots on a timer. | Very fast. Little storage. | A crash loses up to a few seconds of acknowledged edits. Breaks the durability promise. |
| Write the log first, then acknowledge | Append each edit to a replicated log, wait for it to commit, then ack and broadcast. Snapshots every N edits. | No acknowledged edit is lost. Recovery is snapshot plus log tail. The log doubles as version history. | A write on every edit (about 1M a second in total), so use batching (group commit) and a log store built for appends. |
| Store only snapshots, no log | Save the whole document often and drop the edits. | Small and simple. | No history, no undo, and no way to repair a crash that happened mid-merge. |
| Log first, plus fencing by epoch | As option 2, and every append carries the owner epoch. The log rejects an append from an older epoch. | A paused old owner cannot corrupt the log after a new one took over. | An epoch check on each append, and a lease to hand out the epoch. |
The append-only log is the source of truth (the same idea as event sourcing and a write-ahead log). We acknowledge only after it is replicated, so any edit the user saw confirmed survives a crash. A snapshot every 1,000 edits caps replay at about 100 KB, so recovery takes seconds.
The epoch is a fencing token. When a new owner takes a document, the epoch goes up. If the old owner was just paused and wakes up, its appends carry the old epoch and are rejected. Without this, two servers could number different edits with the same revision and the document would fork.
| Moment the owner dies | State left behind | Recovery |
|---|---|---|
| Before the log append | The edit was never acknowledged | The client still has it pending and resends it with the same opId to the new owner. |
| After the append, before the ack | Edit is in the log, sender not told | The sender resends the same opId. The new owner sees it in the log and returns the existing revision (no duplicate). |
| After the ack, before the broadcast | Edit in the log, others not told | Other clients see a revision gap on reconnect and fetch the missing edits from the log. |
| History and undo | How it works |
|---|---|
| Version history | A named version is just a (document, revision) pointer. To view it, load the nearest snapshot and replay to that revision. |
| Restore | Compute the changes from the current text to the old text and apply them as new edits. The log never rewinds. |
| Per-user undo | Undo creates the inverse of your edit, transformed against everything that happened since. It does not remove anyone else's work. |
| Compaction | Old log ranges are folded into a snapshot, and fine-grained history is kept only for recent weeks, to control the 13 TB hot log. |
The problem: A user edits for three days on a plane and then reconnects. Another has their access removed while the document is open. Both are about the server not trusting the client. Invariant: no edit is applied without a current permission check, and no edit that was made offline is silently dropped.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Block editing offline | The editor is read-only without a connection. | No merge problem. | Fails a core user need, and users will switch tools. |
| Queue offline edits and rebase on reconnect (OT) | Keep the local edits with ids. On reconnect, send them from the last known revision. The server rewrites them against every edit that happened meanwhile. | Edits are not lost. Uses the same engine as online editing. | A long offline period means rewriting against thousands of edits, and the result can surprise the user. |
| CRDT merge on reconnect | Exchange the sets of edits and merge them. The result does not depend on order. | Merges are order-independent. Offline-first is natural. | More metadata kept on the client, and a long offline session can still produce a confusing text. |
| Keep both versions and ask the user | On a large conflict, save the offline copy as a separate document or a suggestion. | Safe: nothing is lost and nothing is decided silently. | Manual work for the user. Use only for big conflicts. |
The same engine handles online and offline: an edit has an id and a base revision, and the server rewrites it against everything after that revision. A size limit protects the system: if an offline session is too far behind (for example thousands of edits), the server offers a conflict copy rather than a huge rewrite that may not match what the user meant.
For security, the rule is never trust the client. The session server checks the role on every edit (not only at connect), so removing access takes effect on the next edit and the server closes the socket. It also checks sizes, rates and edit shape, because a client can send malformed or huge edits.
| Security topic | What we do |
|---|---|
| Permission checks | Role checked at the gateway and again at the session server on every edit. Roles are cached with a short TTL and a revoke message closes the socket. |
| Link sharing | Random, long link ids that carry a role, can be disabled, and are rate limited against guessing. |
| Abuse and limits | A cap on edit size, edits per second per client, and document size. Over the limit, drop the edit and warn the user. |
| Data at rest and audit | Encrypt logs and snapshots at rest, write an audit trail of share and permission changes, and honour deletion and retention rules (check with legal for what applies). |
| End-to-end encryption | It would stop the server from transforming edits, so it needs a different design (client-side CRDT). Out of scope here. |
A teaching model with fixed edits (no random numbers). Small numbers under a letter in CRDT mode are its permanent id (counter·site). In OT mode a client sends one edit at a time and rewrites what it receives against its one pending edit. Real systems handle long runs of edits, rich text and many clients.
| Bottleneck | Fix |
|---|---|
| A hot document with thousands of viewers (100,000 messages a second from one server) | Editors stay in the session. Viewers connect to a fan-out tier of edge nodes. The session server sends a handful of messages. |
| 10 million open sockets | About 200 gateways at 100,000 sockets each. Gateways are stateless and hold only the connection, so they scale out and restart easily. |
| 1 million log appends a second | Group commit: batch many edits per write (for example every 10 ms). Merge bursts of typing. Use an append-friendly log store, partitioned by document. |
| Log grows by about 0.4 TB a day (13 TB hot, 30 days) | Snapshots every 1,000 edits, fold old log into snapshots, keep fine-grained history for recent weeks only, and tier cold documents to cheaper storage. |
| Reconnect storm after a session server or gateway fails | Jittered backoff on clients, a rate limit at the gateway, cached snapshots, and fast reload from the log tail. |
| One uneven server (a few huge documents on one machine) | Consistent hashing with virtual nodes, and the ability to move a single document by closing it and letting it reopen elsewhere. |
| Transform cost with a very long offline rebase | Cap the rebase size, process it off the hot path, or offer a conflict copy. Keep the transform linear in the number of missed edits. |
| Failure | How the design copes |
|---|---|
| A session server crashes | Its lease expires, another server takes the documents with a higher epoch, loads snapshot plus log tail (about 10 seconds for 50,000 documents), and clients reconnect from their last revision. |
| A session server is paused (garbage collection) and then resumes | It still believes it owns the document. Its appends carry the old epoch and the log rejects them. It drops its sockets and reloads. |
| A gateway crashes | Clients reconnect to another gateway. No document state lives there, so nothing is lost. |
| The log store is unavailable | Editors become read-only for a moment, with a clear message. Local edits stay pending on the client and are sent when the log returns. We never acknowledge without a commit. |
| A client sends the same edit twice (retry) | The edit id is already in the log, so the server returns the existing revision and does nothing else. |
| A bug in the transform code makes copies diverge | Clients and server compare a hash of the text at a revision. A mismatch triggers a full reload from the snapshot and an alert. Property tests with random edits catch most cases before release. |
One session server owns each document, numbers every edit, rewrites late edits against the ones they missed, writes them to a replicated log before acknowledging, and broadcasts them. Clients apply their own edits at once. Snapshots bound recovery, an epoch fences stale owners, and a fan-out tier serves viewers of hot documents.
| Decision | What we gain | What it costs |
|---|---|---|
| One writer per document | Ordering with a local counter, no distributed transaction, simple OT | A pause of several seconds when the owner fails, and hot documents need a separate tier |
| OT instead of CRDT | No metadata per letter, small documents, easy permission checks on the server | A central order, and transform rules that must be tested for every pair |
| Log first, then acknowledge | No acknowledged edit is ever lost, and the log is the history | A write on every edit (a million a second), solved with group commit |
| Optimistic local apply | Typing feels instant | The client must rewrite incoming edits against its pending edit |
| Rebase offline edits, conflict copy if huge | Offline work is kept and merged by the same engine | A long offline merge can surprise the user |
The heart of the question. Be ready to walk an example by hand.
Show that you know both approaches and what the client does while waiting.
Where the single-owner design is tested.
What happens when it goes wrong, and how you prove it will not lose work.
A change in requirements is a test of whether you understand why your design looks the way it does.
| New requirement | What changes in the design |
|---|---|
| Offline-first and peer-to-peer (no central server) | Switch to a sequence CRDT with letter ids. Replicas exchange edits directly or through a relay, and tombstone cleanup needs a version vector. Permissions become harder because there is no server to enforce them. |
| Rich text with tables and images | A richer edit language (format range, split and merge paragraphs, table row edits) and a transform rule for each pair. Often a tree document model. Same session server, log and snapshots. |
| Comments and suggestions | Comment anchors are positions that must be transformed with every edit. Suggestions are edits stored as proposals and applied or discarded later. Store them with the document, with their own permissions. |
| Spreadsheet instead of text | Edits are cell writes and row or column moves. Concurrent writes to one cell need a rule (last write by revision wins), and structure edits (insert row) are transformed like text inserts. |
| Multi-region active-active editing of one document | Either keep one owner region per document and route everyone to it (higher latency for far users), or use a CRDT and replicate between regions. Say the trade-off: consistency and simplicity versus latency. |
| End-to-end encryption | The server can no longer read or transform edits, so it only orders and stores encrypted blobs, and the clients must use a CRDT. Search, history diffing and server-side permissions on content are limited. |
| 10,000 simultaneous editors | Shard the document into sections with separate owners, or restrict most users to view-only. Batch edits in short rounds and send diffs. Accept that cross-section edits need coordination. |
| Real-time code editor with language features | The same engine for text, with extra services (language server, run) on the side. Cursors, selections and lock-free edits matter more, and conflicts are more visible to users. |
| Area | Weak | Good | Great |
|---|---|---|---|
| Requirements | Starts drawing at once. Never asks about offline, rich text or the number of editors. | Asks about editors, latency, offline and history, and writes the scope down. | Also settles intent versus convergence as the key requirement, permissions on live sessions, and a hot-document case, and says what is out of scope. |
| Estimation | No numbers, or only a user count. | Gets edits per second, connections and gateways, and log growth. | Shows that one document is only about 10 edits a second so one owner is cheap, finds the hot-document fan-out as the real limit, and sizes snapshots and the hot log. |
| Core problem | Sends raw edits or last write wins, and does not see the divergence. | Names OT or CRDT and gives a simple example of an insert shifting an index. | Walks a concrete example by hand, states the convergence property, explains the single order and the client state machine, and compares OT with CRDT honestly. |
| Reliability | Saves the document to a database now and then. | Uses an append-only log and snapshots. | Logs before acknowledging, dedups by edit id, fences stale owners with an epoch, and explains each crash window. |
| Trade-offs | Presents one design as obviously best. | Compares OT and CRDT and picks one with a reason. | Says what would flip the choice, what the single owner costs, and how long a failover pauses editing. |
| Operations and security | No testing or monitoring plan, trusts the client. | Checks permissions server side and monitors latency. | Property-based tests and hash checks for divergence, revoke closes sockets, limits on edit size and rate, and a safe migration plan. |
| Mistake | Do this instead |
|---|---|
| Saying “last write wins” or “lock the document” | Explain that both fail the goal: either work is destroyed or people cannot type together. Move straight to merging edits. |
| Sending edits by index with no rewriting | Show the “ABC” example where an index points at a different letter once the text has moved, and introduce transformation or ids. |
| Making the local keystroke wait for the server | Apply local edits at once (optimistic) and reconcile later. Waiting for a round trip makes typing feel broken. |
| Acknowledging before the edit is durable | Append to the replicated log first, then acknowledge, then broadcast. Otherwise a crash loses an edit the user saw confirmed. |
| Ignoring the paused old owner | Fence every append with the owner epoch so a stale server cannot fork the document. |
| Giving a hot document one server for editors and viewers | Keep editors in the session and serve viewers through a fan-out tier. Do the 100,000 messages a second sum. |
| Forgetting permissions on a live session | Check the role on every edit and close the socket on revoke, not only when the document opens. |
| Presenting CRDT or OT as free | Name the cost: a central order and transform code for OT, per-letter metadata and tombstones for CRDT. |
baseRevision and an edit id.The rewriting rules and the client-server model used here.
The alternative: letter ids so edits commute without a central order.
How every client stays connected for real-time edits.
The idea behind logging each edit before acknowledging it.
The operation log as the source of truth and the history.
How a document is routed to its one session server.
What stops a paused old owner from appending after a new one took over.
A growing counter that orders events, like our revision numbers.