Courses / System Design Interview / Chapter 38
Module 8 · Design Problems III: Links, Crawling and Collaboration · Chapter 38 of 49
Design Collaborative Editing like Google Docs
Builds on Core Concepts: RPCs, Consistency, Failures and Time, Back-of-the-Envelope Estimates, Databases: Choosing, Replicating and Partitioning, Design a Distributed Key-Value Store, Distributed Task Schedulers and Design a Messaging App like WhatsApp. Next up: Design a Deployment System.
Part 1 · Requirements and estimates
What the editor must do
A shared document editor lets several people type into the same text at once and see each other's changes within a fraction of a second. The whole design exists to stop the failure everyone has met, where two people edit one paragraph and one person's work vanishes.
The functional requirements are: create and open a document; edit it with inserts and deletes of text; see other people's edits live; see where other people's cursors are, called presence; keep a history so that an earlier version can be restored; and keep working through a short loss of network, with the edits merged when the connection returns. Rich formatting, comments, suggestions and spreadsheets are out of scope. We design for plain text and note where formatting would change the answer.
The non-functional requirements decide the design more than the features do. Three of them matter most. First, convergence: when everyone has seen every edit, everyone must see exactly the same text. A document that looks different on two screens is broken, however fast it is. Second, intention preservation: if Asha types a word in the middle of a sentence while Bilal deletes a different sentence, both edits must survive in the way each person meant them. Third, latency: a person's own typing must appear at once, with no wait for a server, and other people's typing should arrive in well under a second.