0%
System Design Interview Framework: A Repeatable Plan From Requirements to Wrap Up
The Interview Itself
The Framework Step by Step
Walkthrough: A Collaborative Document Editor
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
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
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
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.
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
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
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
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
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
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.
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
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
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
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
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
Checking in
Interview Dialogue
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.
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
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
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
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
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
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
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.
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
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
Offline editing
Interview Dialogue
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
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
The close
Interview Dialogue
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.
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.