Walkthrough: A Collaborative Document Editor

Topics Covered

Requirements and Numbers

The prompt

Scoping the functional requirements

Non functional requirements

The estimate

What has been established

A weaker opening for comparison

Why convergence is stated first

Separating viewers from editors

Confirming the scale before moving on

What the board looks like at this point

API and Data Model

The API

The operation format

The data model

Where the data lives

Compaction

The state of the board

Why the protocol comes before the boxes

What the candidate did not model

Reading the protocol back against the requirements

Batching keystrokes

Identifiers for documents and operations

Keeping the step short

The High Level Design

The collaboration tier

Why a single owner is reasonable

The write path

Presence and viewers

Snapshots and history

Checking in

What the design avoids

Scaling the tier

Where the in memory state lives

Keeping recent operations in memory

Choosing gateways and connection handling

Permissions on the live path

Counting the servers

Deep Dive: Resolving Concurrent Edits

The problem in one example

Two families of approach

Transformation on the client too

Ties and intent

Formatting and structure

What the deep dive showed

A follow up challenge

Keeping the explanation concrete

Why not lock or take turns

Testing convergence

Summarising the deep dive

Failures, Offline Edits and Wrap Up

Owner failure

Client disconnects

Offline editing

Other failures

The trade offs

The close

Looking back at the session

What made it strong

Common mistakes on this problem

Monitoring the system

Questions the interviewer might still ask

Practising this walkthrough

The second walkthrough is a collaborative document editor, the kind of tool where several people type into the same document at once and see each other's changes within a fraction of a second. It is a favourite interview problem because it looks like a simple product but contains a genuinely hard core: keeping many copies of the same text consistent while everyone edits them concurrently. It also exercises real time delivery, storage of history and failure handling, so it touches almost every part of the framework.

As with the ticketing walkthrough, read the dialogue as an example of the shape of a strong session, not as a script. The specific choices matter less than the way each one is reached.

The prompt

The interviewer says: design a collaborative document editor, like the ones people use to write documents together in a browser. Several people can edit the same document at the same time and see each other's changes live. The prompt names the core difficulty directly, which is common for this problem. The candidate still needs to scope the product around it.

Scoping the functional requirements

Interview Dialogue

CandidateLet me confirm the core. Users open a text document, and several of them can edit it at the same time, seeing each other's changes within about a second. Is it plain or rich text?
InterviewerClick to reveal answer
CandidateGood. Alongside editing, I would include presence, seeing who else is in the document and where their cursors are, and version history, so users can see and restore earlier versions. I would leave out comments, suggestions mode, spreadsheets, embedded media and permissions management beyond a simple check. Does that work?
InterviewerClick to reveal answer
CandidateI would like to support short offline periods, such as a train journey, with edits merged when the user reconnects. Long offline editing with big conflicts I would treat as a stretch.
InterviewerClick to reveal answer
Show all answers
Scope the editor to co editing, presence and history.

In about a minute, the candidate has defined three features, editing, presence and history, and a requirement about offline use that the interviewer raised. Treating formatting as another kind of edit, as the interviewer suggested, keeps the core problem small without losing anything important.

Non functional requirements

Interview Dialogue

CandidateThe most important property is convergence: after everyone stops typing, every copy of the document must be identical. A document that ends up different on two screens is a serious bug. Second, intent preservation as far as possible, so if I type a word in the middle of a sentence, it ends up where I meant it even if someone else edited before it.
CandidateThird, latency: my own typing must appear instantly, which means it is applied locally first, and other people's edits should appear within a few hundred milliseconds. Fourth, durability: once an edit is acknowledged, it must never be lost. And availability: a server failure should cause at most a short pause, not lost work.
InterviewerClick to reveal answer
CandidateI will assume most documents have one or two editors, and design for up to around fifty concurrent editors on a busy one, with more viewers in read only mode.
InterviewerClick to reveal answer
Show all answers

The candidate stated convergence first, because it is the property that defines the problem. They also distinguished local latency, which is solved by applying edits on the client immediately, from remote latency, which is a server problem. That distinction is one of the first signs that a candidate has thought about this kind of system before.

The estimate

Interview Dialogue

CandidateLet me size it. Say ten million daily users, with about two million documents open at peak. Most have one editor, so perhaps three million editing sessions at peak. A typing user sends a few operations a second, but clients batch keystrokes into an operation every hundred milliseconds or so, so call it two operations a second per active editor, and maybe a third of sessions are actively typing at any moment. That is about two million operations a second across the system.
CandidateEach operation is small, under a hundred bytes. So the total is a couple of hundred megabytes a second of operations, which is a lot but spreads evenly across millions of documents. Storage: if operations are kept for history and compacted into snapshots, a typical document might accumulate a few megabytes of history a year.
InterviewerClick to reveal answer
CandidateNot the aggregate load, which partitions perfectly by document. The hard part is inside each document: ordering and merging concurrent edits from up to fifty people with low latency. The design should make each document's work happen in one place.
Show all answers
Many documents, few editors each, small frequent operations.

The estimate again does its real job: it shows that the system as a whole is large but easy to partition, and that the difficulty is per document. The conclusion, that each document's work should happen in one place, is the seed of the main design decision.

What has been established

About six minutes in, the board shows the three features, the offline requirement, five non functional requirements in order, and the key numbers: millions of documents, up to fifty editors each, about two million small operations a second overall. Most importantly, the candidate has said where the difficulty lives and hinted at how to approach it.

A weaker opening for comparison

A weaker opening would list every feature of a modern document suite, from comments to templates, estimate total storage for all documents ever written and describe the system as a generic web app that saves the document on each change. That candidate would reach the high level design with no mention of concurrent editing, convergence or ordering, and the interviewer would have to steer them there, which is a signal for a lower rating.

Why convergence is stated first

It is worth dwelling on why the candidate led with convergence rather than latency or scale. Every other property can be traded to some degree: a little more latency, a slightly shorter offline window, fewer editors per document. Convergence cannot be traded. If two editors end up seeing different text, the product is broken in a way users will notice and never trust again. Leading with it tells the interviewer that the candidate sees the problem's true constraint, and it gives every later decision something firm to point back to.

Separating viewers from editors

The candidate also separated editors from viewers in passing. That small distinction pays off later. Viewers only need to receive operations, so they can be served by a lighter broadcast path and do not take part in ordering. A presentation with two editors and two thousand viewers is then easy, while a document with fifty active editors is the case that needs careful handling.

Confirming the scale before moving on

Before leaving the estimate, the candidate could ask a quick question: is up to fifty concurrent editors the right ceiling, or do you have a case like a company wide document with hundreds of people typing? Interviewers sometimes have a specific scenario in mind. If the answer were hundreds of active editors, the single owner would still work, but the candidate would mention batching broadcasts and throttling presence more aggressively. Asking takes a few seconds and either confirms the plan or reveals a twist early, when it is cheap to adjust.

What the board looks like at this point

The corner of the board now reads: co edit, presence, history, short offline; convergence, intent, local instant and remote fast, durable, available; ten million daily users, two million open documents, up to fifty editors, two million small operations a second, partitions by document. Every later decision will point back to one of these lines.

Separate local and remote latency

In collaborative editing, your own keystrokes must appear instantly, which the client handles by applying them locally first. Other people's edits need to arrive within a few hundred milliseconds, which is the server's job. Saying this early shows you understand how these systems actually feel to users.

The API and data model for the editor are different in shape from a typical request and response product, because most of the interaction happens over a persistent connection rather than discrete calls. The candidate keeps this step short but makes two decisions that the rest of the design depends on: how operations are identified and ordered, and how a document is stored.

The API

Interview Dialogue

CandidateThere are a few ordinary endpoints: GET documents slash id for metadata and the latest snapshot, GET documents slash id slash history for the version list and POST documents slash id slash restore to restore a version.
CandidateThe interesting part is the live session, over a WebSocket. The client opens a session for a document and sends operations. Each operation carries the client's id, a client sequence number and the server sequence number of the last operation the client had seen when it made the edit, which I will call the base. The server replies with an acknowledgement that gives the operation its server sequence number, and broadcasts it to everyone else in the document. Presence updates, cursor positions, go over the same connection but are not stored.
InterviewerClick to reveal answer
CandidateThe client sequence makes retries safe: if the connection drops and the client resends, the server can recognise an operation it has already applied. The base tells the server what the client knew when it made the edit, so the server knows which concurrent operations it must be transformed against.
Show all answers

The interviewer's question went straight to the most important detail, and the candidate's answer covered both purposes in two sentences. The base sequence is the key to the whole conflict resolution scheme, and introducing it in the API makes the later deep dive easy to follow.

The operation format

Interview Dialogue

CandidateAn operation is something like insert text at position, delete a range, or apply a format to a range. Positions are offsets into the document as the client saw it at its base. Operations are small, usually a few characters plus a position.

Stating that positions are relative to the client's base is important. It is the reason concurrent operations need transforming: a position that was correct when the client made the edit may be wrong after someone else's insert has been applied.

The data model

Interview Dialogue

CandidateFor storage, a document is a snapshot plus the operations after it. The operations table is keyed by document id and server sequence number, with the operation, the author and a timestamp. It is append only. Every few hundred operations, the server writes a snapshot of the full document at that sequence number to a snapshot store.
CandidateLoading a document means reading the latest snapshot and replaying the operations after it, which is never more than a few hundred. Version history comes from the snapshots plus the log: any past version can be rebuilt by replaying from the snapshot before it.
InterviewerClick to reveal answer
CandidateWe need the log anyway for ordering and for clients that reconnect and need the operations they missed. Keeping it also gives us history almost for free. Storing only the latest text would lose both.
Show all answers
A document is a snapshot plus the operations after it.

The candidate chose an append only log with periodic snapshots, which is the standard model for this problem, and justified it with three uses: ordering, catching up reconnecting clients and history. Explaining why the simpler alternative falls short makes the choice convincing.

Where the data lives

Interview Dialogue

CandidateThe operation log needs fast appends and range reads by document and sequence, so a wide column store or a partitioned relational table both work, partitioned by document id. Snapshots are larger blobs, a few kilobytes to a few megabytes, so they go in object storage with a pointer in a metadata table. Document metadata, titles, owners and sharing, sits in an ordinary relational database.

Each kind of data goes to a store that suits its access pattern, with a sentence of reasoning. The candidate did not spend time choosing a specific product, which would not change the design.

Compaction

Interview Dialogue

InterviewerClick to reveal answer
CandidateFor active documents it grows, but we can compact old history. Operations older than, say, thirty days can be collapsed into hourly snapshots, keeping fine grained history only for recent edits. That keeps storage proportional to how much history users actually browse.
Show all answers

The interviewer probed a natural weakness of the log model, and the candidate answered with a concrete compaction policy and a product reason for it.

The state of the board

About twelve minutes in, the board has a short list of endpoints, the live session protocol with client sequence and base, the operation log and snapshot model and the stores for each kind of data. The core concepts for the deep dive, sequence numbers, bases and operations with positions, are all defined. The high level design can now build on them directly.

Why the protocol comes before the boxes

Some candidates draw the architecture before defining what flows through it. For this problem, defining the operation and its identifiers first pays off, because almost every later question, about ordering, retries, reconnects and offline edits, is answered in terms of client sequence, server sequence and base. Without those terms, the high level design would be harder to explain and the deep dive would have to stop and define them anyway.

What the candidate did not model

The candidate did not design tables for comments, suggestions, templates or detailed sharing permissions, all of which were scoped out or treated simply. Nor did they model formatting in detail beyond saying it is a range operation. Each omission keeps the step focused on the parts that the deep dive will depend on, and each could be added later without changing the core model.

Reading the protocol back against the requirements

A quick check maps the protocol to the requirements. Convergence: the server assigns one sequence per document and the base tells it what to transform against. Intent: transformation shifts positions so edits land where authors meant. Latency: clients apply edits locally and the WebSocket keeps remote delivery fast. Durability: the acknowledgement comes after the log append. Availability: client sequence numbers make resends safe after a failure. Offline: queued operations carry their base like any other. Every requirement has a mechanism, which tells the candidate the model is complete enough to design on.

Batching keystrokes

The candidate mentioned that clients batch keystrokes into an operation every hundred milliseconds or so. This is worth one more sentence because it changes the load considerably. A fast typist produces eight or more keystrokes a second, and sending each one separately would multiply the operation rate and the number of acknowledgements. Merging consecutive inserts into one operation keeps the rate near two a second per editor while still feeling live to collaborators, since a hundred milliseconds is below what people notice.

Identifiers for documents and operations

Document identifiers should be random rather than sequential, so they cannot be guessed and they spread evenly when hashed to owners. Operation identity is the pair of document id and server sequence number, which is unique and ordered within the document, so no separate global operation id is needed. Saying this briefly removes a question the interviewer might otherwise ask.

Keeping the step short

The whole step took about six minutes. Each decision made here, the base sequence, client sequence numbers, the append only log and snapshots, is used again in the high level design, the deep dive or the failure discussion. Nothing was defined only for completeness, which is a good test of whether a data model step is the right length.

The base sequence is the key field

Each operation should carry the server sequence number the client had seen when it made the edit. That base tells the server exactly which concurrent operations the edit must be transformed against, and it also makes reconnects and offline edits work with the same mechanism.

With the protocol and storage defined, the candidate draws the system. The central decision, foreshadowed in the estimate, is that each open document has exactly one server responsible for it at any moment. Most of the rest of the design follows from that choice.

The collaboration tier

Interview Dialogue

CandidateClients connect over WebSockets to a collaboration tier. For each open document, exactly one collaboration server is its owner. The owner holds the document's current state in memory, receives operations from all editors, assigns server sequence numbers, transforms concurrent operations, appends to the log and broadcasts to everyone in the document.
CandidateBecause one server orders all operations for a document, ordering is trivial: it is the order in which the owner processes them. We avoid any distributed agreement on the hot path.
InterviewerClick to reveal answer
CandidateA router. When a client opens a document, it connects to any gateway, and the gateway looks up the owner in a small ownership directory, a key value store mapping document id to server with a lease. If there is no owner, the gateway picks one, by consistent hashing for example, and that server takes the lease. The gateway then forwards the client's connection to the owner, or the client reconnects to it directly.
Show all answers
One owner per open document orders every edit.

The candidate made the key decision explicit, one owner per document, and said what it buys: ordering without distributed coordination. The routing answer named a concrete mechanism, an ownership directory with leases, which will matter in the failure discussion.

Why a single owner is reasonable

Interview Dialogue

InterviewerClick to reveal answer
CandidatePer document, the load is at most fifty editors at a few operations a second, a few hundred operations a second, which one server handles easily. Across documents, ownership spreads over many servers, so the system scales by adding servers. The real risk is not load but failure, which the lease handles, and I will cover that later.
Show all answers

This is a good example of answering a challenge with numbers from the estimate. The single owner is not a bottleneck because the per document load is small, and the candidate named the real risk, failure, rather than pretending there is none.

The write path

Interview Dialogue

CandidateLet me walk one edit. Alice types a word. Her client applies it locally, so she sees it instantly, and sends the operation with her client sequence and base. The owner transforms it against any operations after her base, assigns it the next server sequence, appends it to the log and, once the append is durable, acknowledges it to Alice and broadcasts it to the other editors. Their clients transform it against any of their own unacknowledged edits and apply it.
InterviewerClick to reveal answer
CandidateI would wait for the append before acknowledging, so an acknowledged edit is never lost. Broadcasting could happen slightly earlier to cut latency, but then a crash could show others an edit that is later lost. Since the log append is a few milliseconds, I would keep it simple and broadcast after the append.
Show all answers

The candidate walked the edit end to end, including both client side and server side transformation, and stated a trade off about broadcasting before or after the durable write with a clear choice and reason.

Presence and viewers

Interview Dialogue

CandidatePresence, cursors and who is online, goes through the same owner but is not stored; the owner just relays the latest cursor position for each editor, throttled to a few updates a second. Read only viewers connect to the owner too, or for very large audiences, to a fan out layer that subscribes to the owner's broadcast, so the owner does not hold thousands of viewer connections.

Presence is handled in a sentence, with the right decision that it is ephemeral and need not be stored. The large audience case reuses the fan out idea from real time systems, without adding complexity to the editing path.

Snapshots and history

Interview Dialogue

CandidateThe owner writes a snapshot every few hundred operations, asynchronously, to object storage, and records it in the metadata table. History views read snapshots and replay from the log. Neither is on the typing path.

Checking in

Interview Dialogue

CandidateThat is the design: gateways and a router, one owner per open document holding state in memory, an append only log, snapshots in object storage and a light presence channel. I would like to go deep on how concurrent edits are resolved, transforms versus other approaches. Is that the right area, or would you prefer failure handling?
InterviewerClick to reveal answer
Show all answers

The candidate is about twenty two minutes in, with the deep dive confirmed and failures scheduled after it.

What the design avoids

It is worth noticing what the design does not do. It does not lock documents or paragraphs, which would make collaboration feel clunky. It does not store the whole document on every keystroke, which would waste writes and lose concurrent edits. It does not try to order operations across many servers with a consensus protocol on every edit, which would add latency for no benefit. Each of these is a common first idea, and the single owner design avoids all three.

Scaling the tier

The collaboration tier scales by adding servers, with ownership spreading across them through consistent hashing. When a server is added or removed, some documents move to a new owner, using the same lease handover as a failure. Because most documents are small and idle, moving them is cheap; busy documents can be moved during quiet moments, or left in place until their sessions end.

Where the in memory state lives

The owner holds each open document's current text, its recent operations and the list of connected sessions in memory. For a typical document that is tens of kilobytes; even a large one is a few megabytes. A collaboration server with tens of gigabytes of memory can therefore own tens of thousands of open documents. When a document has had no editors for a few minutes, the owner writes a final snapshot, releases its lease and frees the memory, so idle documents cost nothing. This is the kind of detail that shows the candidate has thought about how many servers the tier needs, which follows directly from the estimate: two million open documents across a few hundred servers.

Keeping recent operations in memory

The owner keeps the last few hundred operations in memory as well as in the log. Most reconnecting clients have been away for seconds, so they can be caught up from memory without touching the log store. Only clients that have been away longer read from the log. This keeps the common case fast and reduces load on storage, at the cost of a little memory per document.

Choosing gateways and connection handling

The gateways terminate WebSocket connections, handle authentication and check that the user may open the document. Keeping these concerns out of the owners means owners only deal with ordering and broadcast. Gateways are stateless apart from their open connections, so they scale horizontally behind a load balancer, and a gateway failure only forces its clients to reconnect, which they already know how to do.

Permissions on the live path

The permission check happens when a session opens, not on every operation, because checking per keystroke would add latency for little benefit. If a user's access is revoked mid session, the metadata service notifies the owner, which closes that session. Mentioning this shows that security has been considered without slowing the hot path.

Counting the servers

A quick sanity check closes the step. Two million open documents at peak, each needing a few tens of kilobytes, is under a hundred gigabytes of state, and about two million operations a second spread over a few hundred servers is several thousand per server, comfortably within reach. Saying this aloud ties the architecture back to the estimate.

One sequencer per partition

When operations within a partition must be ordered but partitions are independent, give each partition a single owner that orders its operations. Ordering becomes trivial, the system still scales across partitions, and the remaining problem is handling the owner's failure, which leases solve.

This is the heart of the problem. Two people edit the same document at the same moment, each based on a slightly different version of the text. How does every copy end up the same, with each person's edit where they meant it? The candidate compares the two main families of approach, chooses one and walks through it.

The problem in one example

Interview Dialogue

CandidateHere is the core case. The document says hello world. Alice and Bob both see version forty. Alice inserts the word big at position six, before world. At the same time, Bob inserts an exclamation mark at position eleven, at the end. If each client applies the other's edit as written, Bob's exclamation mark lands at position eleven of Alice's new text, which is now in the middle of the word world. The copies diverge.
CandidateTransforming fixes this. When the owner receives Bob's insert with base forty, it sees that Alice's insert, sequence forty one, came after Bob's base and before Bob's operation. Alice inserted four characters before Bob's position, so Bob's position shifts from eleven to fifteen. Applied in that form, both copies read hello big world with the mark at the end.
Concurrent edits are transformed so every copy ends the same.

A concrete example makes the problem and the solution clear in under a minute. The candidate used the base sequence defined in the API, which makes the explanation precise.

Two families of approach

Interview Dialogue

CandidateThere are two main families. Operational transformation, which is what I just described: operations carry positions, and a server transforms each one against concurrent operations it had not seen. It relies on a central ordering point, which our single owner provides. And conflict free replicated data types, CRDTs: each character gets a unique, ordered identifier, and inserts refer to neighbouring identifiers rather than positions, so operations can be applied in any order on any replica and still converge, without a central server.
CandidateTransformation is simpler to reason about when there is a central sequencer, and its operations and documents are compact. CRDTs are better when there is no central server, such as peer to peer editing or long offline periods, but they carry metadata for every character and deletions leave markers that must be cleaned up.
CandidateSince we already have one owner per document and short offline periods, I would choose transformation with a central server.

The comparison names the mechanism of each approach, its strengths and its costs, and makes a decision based on the design's existing properties: a central owner and short offline periods. That link back to earlier decisions is what makes the choice convincing.

Transformation on the client too

Interview Dialogue

InterviewerClick to reveal answer
CandidateRight, the client also transforms. Bob's client has his edit pending, unacknowledged. When Alice's operation arrives, Bob's client transforms Alice's operation against his pending edit, so it lands in the right place on his screen. When his own acknowledgement arrives, his pending edit is confirmed. Because the server only ever has one sequence of operations, and each client transforms incoming operations against its own pending ones, all copies converge.
CandidateTo keep this simple, each client has at most one batch of operations in flight at a time, and buffers further typing until the acknowledgement. That limits how much transforming is needed.
Show all answers

This answer covers the part many candidates miss: the client side of transformation. Limiting each client to one in flight batch is a well known simplification, and mentioning it shows familiarity with how real systems keep the algorithm manageable.

Ties and intent

Interview Dialogue

InterviewerClick to reveal answer
CandidateThen there is a tie, and the transform needs a deterministic rule, for example the operation with the lower client id goes first. It does not matter which rule, as long as everyone applies the same one, because convergence requires that every copy makes the same choice. Intent is mostly preserved, since both insertions appear next to each other where both authors put them.
CandidateDeletes overlapping with inserts need similar care: if Alice deletes a range and Bob inserts inside it, the transform keeps Bob's insert at the start of the deleted range rather than losing it.
Show all answers

Ties and overlapping deletes are the standard edge cases, and the candidate handled both with the principle that matters: a deterministic rule applied everywhere.

Formatting and structure

Interview Dialogue

CandidateFormatting operations, such as bold on a range, transform the same way: their ranges shift with inserts and deletes before them. Structural edits, like splitting a paragraph, are inserts of a special character. So the same machinery covers rich text without a separate system.

What the deep dive showed

In about twelve minutes, the candidate explained the core problem with a concrete example, compared the two families of approach on their real trade offs, chose one for reasons rooted in the design and covered the client side, tie breaking, overlapping deletes and formatting. That is mechanism level depth in exactly the area where the problem's difficulty lives.

A follow up challenge

Interview Dialogue

InterviewerClick to reveal answer
CandidateProbably, yes. With long offline periods, a client may build up thousands of operations against an old base, and transforming them all on reconnect gets expensive and the results less intuitive. A CRDT would let the offline copy merge without central transformation. I would consider moving to a CRDT for the document model while keeping the single owner for ordering, persistence and presence, since a CRDT still benefits from a server that relays and stores operations.
Show all answers

The candidate changed the decision when the requirement changed, explained why and kept the parts of the design that still applied. That is exactly the calibrated judgment interviewers look for when they challenge a choice.

Keeping the explanation concrete

Throughout the deep dive, the candidate kept returning to the hello world example rather than describing transformation in the abstract. Concrete examples make a hard topic easy to follow and make mistakes easy to spot, both for the candidate and the interviewer. When a deep dive topic is algorithmic, a tiny worked example is often the clearest way to show understanding.

Why not lock or take turns

Before choosing between transformation and CRDTs, it is worth saying in one sentence why simpler approaches fail. Locking a paragraph while someone edits it is correct but makes collaboration feel slow, since users must wait for each other. Last writer wins on the whole document loses edits. Merging with a text diff after the fact, as version control systems do, produces conflicts that need human resolution, which is unacceptable for live typing. Naming these quickly shows the candidate knows why a specialised algorithm is needed at all.

Testing convergence

The candidate could also mention how they would gain confidence in the transform functions, which are notoriously easy to get subtly wrong. Property based tests generate random concurrent operations from several simulated clients, apply them in different orders through the transform logic and check that every copy ends identical. Running millions of such cases catches edge cases that hand written tests miss. This is a strong addition at senior and staff level.

Summarising the deep dive

Before moving on, the candidate gave a one sentence summary: concurrent edits are transformed against what the sender had not seen, by the owner and by each client, with deterministic tie rules, and a CRDT becomes the better choice only if long offline editing is required. A short summary like this marks the end of the deep dive clearly and makes the interviewer's notes easier to write.

This walkthrough by level

A mid level answer reaches a central server that orders edits and some notion of adjusting positions, with guidance. A senior answer explains transformation with a concrete example, covers client side transformation and tie breaking, and compares it with CRDTs. A staff answer also ties the choice to the offline requirement, explains when it would switch to a CRDT, and plans compaction, failover and the large audience case.

With the deep dive done, the candidate covers what happens when things go wrong: an owner crashing, a client losing its connection and a user editing offline. Then they close with the trade offs and a summary.

Owner failure

Interview Dialogue

InterviewerClick to reveal answer
CandidateIts lease in the ownership directory expires after a few seconds. The next client request for that document goes to a gateway, which finds no valid owner and assigns a new one. The new owner loads the latest snapshot and replays the log after it, which takes a fraction of a second for a few hundred operations. Clients see their connection drop and reconnect, and the gateway routes them to the new owner.
CandidateEach client then resends any operations that were not acknowledged, with their original client sequence numbers and bases. The new owner deduplicates any that were already in the log, using the client sequence, and transforms and applies the rest. Users see a pause of a few seconds and lose nothing they had been told was saved.
InterviewerClick to reveal answer
CandidateThat is why the lease matters. The old owner must stop accepting operations when its lease expires, and log appends should be conditional on the expected next sequence number, so if two owners briefly coexist, only one can append the next operation. The other's append fails and it steps down.
Show all answers
Ownership moves on failure; clients resend what was not acknowledged.

The candidate covered the full failover sequence, from lease expiry to client resend, and then handled the classic follow up about a slow but alive owner with two mechanisms: the old owner respecting its lease and the log rejecting a conflicting append. That second answer is what separates a strong failure discussion from a simple one.

Client disconnects

Interview Dialogue

CandidateIf a client's connection drops briefly, it reconnects and tells the owner the last server sequence it saw. The owner sends all operations after that, from memory or the log, and the client transforms them against its pending edits. It then resends its unacknowledged operations. This is the same mechanism as normal editing, just with a bigger gap.

Offline editing

Interview Dialogue

CandidateShort offline editing works the same way. While offline, the client keeps applying edits locally and queues the operations, all with the base it last saw. When it reconnects, it fetches operations since its base and sends its queue. The owner transforms the queued operations against everything that happened in between. For an hour on a train, that might be a few hundred operations each way, which is fine.
CandidateIf the gap is very large, I would cap it: past a certain size, the client shows the user a warning and offers to merge as a new version they can compare, rather than silently transforming thousands of edits.
Offline edits are just operations that arrive late.

Offline editing is shown to be a natural extension of the same mechanism, with a sensible limit for the cases where automatic merging stops being trustworthy. The product decision, showing a comparison rather than a silent merge, is the kind of user focused judgment interviewers appreciate.

Other failures

Interview Dialogue

CandidateIf the log store is slow or unavailable, the owner cannot acknowledge, so clients keep their edits pending and the UI shows saving. Nothing is lost, because the client still has the edits. If the snapshot writer falls behind, loading gets slower but stays correct. If the ownership directory is unavailable, existing sessions keep working with their current owners, but new documents cannot be opened until it recovers, so it should be replicated.

Each failure is described in terms of what the user sees, and the candidate noted the one component, the ownership directory, whose failure would stop new sessions and therefore needs replication.

The trade offs

Interview Dialogue

CandidateThe three main trade offs: a single owner per document, giving simple ordering at the cost of a few seconds of pause on failover. Operational transformation rather than CRDTs, giving compact documents and simple reasoning at the cost of needing a central server and limiting long offline editing. And acknowledging only after a durable append, giving no lost edits at the cost of a few milliseconds per edit.

The close

Interview Dialogue

CandidateTo summarise: clients apply edits locally for instant feedback and send them over a WebSocket with a base sequence. Each open document has one owner, found through a leased directory, which transforms concurrent edits, orders them and appends them to a log before acknowledging. Every copy converges because there is one sequence and clients transform incoming edits against their pending ones. Snapshots keep loading fast and give history. On failure, ownership moves, clients resend unacknowledged edits and nothing acknowledged is lost. Offline editing reuses the same mechanism, with a limit for very long gaps.
InterviewerClick to reveal answer
Show all answers

Looking back at the session

The time split was roughly six minutes on requirements and numbers, six on the API and data model, ten on the high level design, twelve on the deep dive and nine on failures and the wrap up. As in the ticketing walkthrough, most of the time went to the place where the difficulty lived, and every step was present.

What made it strong

The estimate showed the problem partitions by document, which led directly to the single owner. The API introduced the base sequence, which made the deep dive precise. The deep dive used a concrete example, compared real alternatives and covered the client side. The failure discussion handled the slow owner case. And the close restated the design in terms of convergence, latency and durability.

Common mistakes on this problem

Common mistakes include saving the whole document on each change and letting the last write win, which loses edits. Locking paragraphs. Describing transformation without a concrete example, which often hides confusion. Forgetting the client side of transformation. Ignoring what happens when an owner is slow rather than dead. And spending the deep dive on presence cursors, which are easy, instead of concurrent edits, which are hard.

Monitoring the system

To know the design is working, the candidate would track a few signals: time from an edit to its broadcast, acknowledgement latency, the number of reconnects and failovers, the size of client resend queues and, most importantly, convergence checks. Clients can periodically send a hash of their document at a given sequence number, and the owner compares it with its own; a mismatch indicates a transform bug and triggers a forced reload of that client plus an alert. That check turns a silent, trust destroying bug into a visible, fixable one.

Questions the interviewer might still ask

How would you add comments? Comments anchor to a range, which shifts with edits exactly like a formatting operation, so they reuse the transform machinery. How would you support undo? Each client keeps its own operations and undo applies an inverse operation, transformed against everything since, so undo only affects your own edits. Answering these in a sentence or two, using parts already on the board, shows that the design is coherent.

Practising this walkthrough

Try running this problem yourself without the dialogue, then compare. Check whether you found the per document ordering problem early, whether you used a concrete example in the deep dive and whether you handled the slow owner. Those three habits carry over to many other problems with a single leader per partition.

Then try a variation, such as hundreds of active editors or a week of offline editing, and see which decisions change and which stay the same.

Plan for the slow owner, not just the dead one

Leases alone are not enough if an old owner keeps working after its lease expires. Make log appends conditional on the expected next sequence number, so two owners cannot both write. The same fencing idea applies to any single leader design.