KatInterview

Build a Multi-User Live Text Editor That Never Loses Edits

System DesignModel answer
MediumModel answerSystem Designsystem-designreal-timecollaboration

Last updated

Design a browser-based rich-text editor where many people edit one document simultaneously, stay in sync, keep durable history, and survive disconnects and server failures.

Design a web-based word processor where several people can work in the same document at once. Every collaborator should see the others' changes within moments, all open copies must converge to identical content, and no edit that the system has confirmed may ever be lost.

Treat the following scope as assumptions and confirm them before designing:

  • Users create rich-text documents (plain text plus bold, headings, lists) and open them in a browser.
  • Anyone with edit rights can type concurrently, including at the very same position.
  • Collaborators can see who else is in the document, along with their cursors and selections.
  • An owner shares a document with named people as viewer, commenter or editor.
  • Users can browse a document's version history and restore an earlier version.
  • A client that briefly goes offline keeps accepting local edits and catches up on reconnect.

Your answer should cover:

  1. Requirements and a rough capacity estimate (state your own numbers and label them as assumptions).
  2. Main components and the data model.
  3. How concurrent edits are ordered and merged, and why you chose that approach over the main alternative.
  4. How documents and history are stored.
  5. How the system scales and recovers from failures.

Out of scope unless raised: comment threads, spreadsheets, slides, cross-document search.

Questions worth asking up front: how many simultaneous editors per document and how large a document can get; how long a client may stay offline; the target latency for propagating an edit; how fine-grained and how long-lived history must be; whether link or organization-wide sharing exists and whether revoking access must cut off an already open session.

Hints

Hint 1

Rule out locking and last-write-wins first by saying what each does to two people typing at the same spot, then pick either operational transformation with a central sequencer or a sequence CRDT and commit to it.

Hint 2

Separate the data into three kinds: durable edits (append-only log plus periodic snapshots), ephemeral presence and cursors (in-memory, never persisted), and metadata and permissions (a regular database). Version history and fast loading both fall out of the log-plus-snapshot design.

Hint 3

Distinguish scaling across millions of documents (shard by document ID, route each document to one owner process) from the single hot document with many editors (one sequencer is fine for edits, but fan-out and presence need batching and throttling). For failures, think about idempotent resubmission with client-generated operation IDs and how a new sequencer takes over without forking history.