Scrivio Interview library
DesignFoundations7 min read · updated 13 November 2026

A collaborative document editor lets several people type in the same document at once and see each other's changes and cursors within a fraction of a second, while keeping full history and surviving brief network drops.

Design the main components, API and data model of a collaborative document editor for documents with up to 100 simultaneous editors.

Clients send small operations, such as insert text at a position or delete a range, over a WebSocket to a session service, where one owner per document, chosen by document id, puts the operations in a single order, stores each one durably and broadcasts it to the other editors. The data model is a documents table with permissions, an append-only operation log keyed by document and revision, and periodic snapshots, so opening a document loads the latest snapshot plus the few operations after it and then joins the live session at that revision. Cursors and presence travel through the same session but are never stored.

Why this question is asked

Shared editors feel simple to use and are surprisingly subtle to build: several people change the same text at the same moment, everyone must end with the same document, and nobody should lose a keystroke when their Wi-Fi drops. Interviewers ask for the design because it combines real-time messaging, ordering, storage and permissions in one product. In this answer, we will set the requirements, lay out the components, define the API and data model, follow a document from opening to editing, and then handle presence, durability, permissions and failures.

1Requirements and Rough Numbers

Up to 100 people edit one document at once, and each sees others' changes within about 200 ms. Every change is kept, so we can show history and restore versions. A brief network drop must not lose edits. Most documents have one or two editors at a time; the 100-editor case is rare but must work.

A fast typist produces about 5 to 10 operations per second, so a document with 100 active editors could see up to 1,000 operations per second at peak, each broadcast to 99 others, which is around 100,000 small messages per second for that one document. The operations themselves are tiny, around 50 to 100 bytes, so storage per document grows slowly, but over years a busy document collects millions of operations, which is why we need snapshots.

2The Main Components

Clients hold a WebSocket open to a gateway, which authenticates them and routes each document's traffic to the session service instance that owns that document. Ownership is decided by document id, for example with consistent hashing or a lease in a coordination store such as etcd, so exactly one instance orders a given document's operations at a time. Having one owner is what makes ordering simple: whoever owns the document assigns each accepted operation the next revision number.

Behind the session service are two stores. The operation log is append-only and keyed by document id and revision; PostgreSQL works well at moderate scale, and Cassandra or a similar wide-column store suits very large volumes. Snapshots, the full document content at a revision, go to object storage such as S3 with their location recorded in the database.

Step throughCollaborative editor components
  1. Editor clientapplies own edits at once, keeps unacknowledged operations
  2. WebSocket gatewayauthentication, routes by document id
  3. Session serviceone owner per document: orders, stores, broadcasts
  4. Operation logappend-only, (document id, revision), PostgreSQL or Cassandra
  5. Snapshotscontent at a revision, in S3, every N operations
  6. Document metadataowner, permissions, title, in PostgreSQL

6 layers, from the top down. Step through them one at a time.

Ordering lives in exactly one place per document.

3The API and the Data Model

Ordinary actions use REST: create a document, list documents, change sharing, list history, restore a version. Live editing uses messages on the WebSocket. Each operation a client sends names the revision it was based on, so the server knows which other operations it has not seen yet.

Java
POST /documents -> { id: "d_42" }
GET /documents/d_42/history?cursor=... -> revisions with author and time
POST /documents/d_42/restore { revision: 1800 }
// WebSocket messages
-> { type: "join", doc: "d_42", fromRevision: 2000 }
<- { type: "ops", ops: [ ...revisions 2001 to 2004... ] }
-> { type: "op", clientOpId: "c7-15", baseRevision: 2004, op: { insert: "cat", at: 10 } }
<- { type: "ack", clientOpId: "c7-15", revision: 2005 }
<- { type: "presence", user: "u9", cursor: 57 } // never stored
CREATE TABLE documents (id TEXT PRIMARY KEY, owner_id TEXT, created_at TIMESTAMPTZ);
CREATE TABLE doc_acl (doc_id TEXT, user_id TEXT, role TEXT, PRIMARY KEY (doc_id, user_id));
CREATE TABLE operations (doc_id TEXT, revision BIGINT, author_id TEXT, op JSONB, created_at TIMESTAMPTZ,
PRIMARY KEY (doc_id, revision));
CREATE TABLE snapshots (doc_id TEXT, revision BIGINT, s3_key TEXT, PRIMARY KEY (doc_id, revision));

The primary key (doc_id, revision) does real work: it makes a duplicate revision impossible, so even a confused second owner cannot write two operations with the same number.

4Opening a Document and Editing It

Opening a document reads the newest snapshot, say at revision 2000, and the operations after it, perhaps 4. The client builds the current text and joins the session from revision 2004. Loading never replays the whole history, because a snapshot is taken every few hundred operations.

When the user types, the client applies the edit to its own copy immediately, so typing feels instant, and sends it with its base revision. Meanwhile, another editor's operation may have reached the server first. The server places the new operation after everything already accepted, adjusting its position if needed (the technique, operational transformation, is its own topic), stores it, acknowledges it with its revision, and broadcasts it. Each client then reconciles its pending local edits with the server's order, so all copies converge.

Step throughOpening, typing and receiving an acknowledgement
Client ASession ownerOperation logClient B
join d_42 from revision 2004
user types: apply locally at once
op insert 'cat' at 10, base 2004
adjust against ops after 2004, assign 2005
append (d_42, 2005)
stored
ack revision 2005
broadcast op 2005

8 messages in order. Play them, or step through them one at a time.

The acknowledgement is sent only after the operation is stored.

5Presence, Durability and Permissions

Presence means cursors, selections and the list of who is viewing. It changes constantly and has no value later, so the session broadcasts it, perhaps throttled to 10 updates a second per user, and never writes it to the log. When someone disconnects, their presence simply times out.

Durability has one rule: an operation is acknowledged only after it is stored in the log. If the server crashes after storing but before acknowledging, the client resends with the same clientOpId, and the server recognises the duplicate. If it crashes before storing, the client still holds the operation as unacknowledged and resends it. Either way nothing is lost.

Permissions are checked when a client joins, and again for each operation, because access can be revoked while a session is open. A viewer may receive operations but any operation they send is rejected. Because every operation records its author and time, the log doubles as an audit trail, and restoring a version means computing the content at an old revision and saving it as a new operation, so history is never rewritten.

6Failures and Trade-offs

If a session owner fails, another instance takes over the document's lease, loads the latest snapshot plus the log, and continues from the last stored revision. Clients reconnect, send their pending operations with their base revision, and the new owner adjusts and stores them. Users see a pause of a second or two, not lost work.

The main trade-off is the single owner per document. It makes ordering simple and correct, but one very popular document can overload one instance, which is why very large audiences are usually handled with a separate broadcast tier. For a design with up to 100 editors, a single owner per document is comfortably enough.

7Follow-up questions

Why not let clients send operations to each other directly?

Without a central order, every client must handle every possible interleaving of concurrent edits, which requires more complex algorithms such as CRDTs, and we still need a server for storage, permissions and history. A central owner keeps clients simple and gives us one place to check permissions and store the log.

How often should we take snapshots?

Often enough that opening a document never replays more than a few hundred operations, for example every 500 operations or every few minutes of activity, whichever comes first. Snapshots are cheap to write to S3 and make loading fast, and old ones can be kept for version history.

How do you handle a user who edits offline for a minute?

The client keeps queuing operations with their base revision. On reconnect, it fetches the operations it missed, reconciles its queue with them, and sends the queue. For short gaps this works with a central-server design; very long offline sessions are harder and often lead teams to CRDTs.

8Conclusion

In this answer, we designed a collaborative editor around one session owner per document that orders small operations, stores each one before acknowledging it, and broadcasts it to all editors over WebSockets. The data model has document metadata with permissions, an append-only operation log keyed by document and revision, and periodic snapshots so loading stays fast. Presence is broadcast but never stored, permissions are checked on join and per operation, and clients keep unacknowledged operations so that reconnects and owner failures never lose edits.

What to say in the interviewAbout 80 seconds aloud

Open with

I would model edits as small operations, like insert text at a position or delete a range, sent over a WebSocket. A gateway routes each document to one session owner, chosen by document id with consistent hashing or a lease, and that owner gives every accepted operation the next revision number, so there is one order.

Then, if they want more

It stores the operation in an append-only log keyed by document id and revision, then acknowledges it and broadcasts it to the other editors. The data model is documents with an ACL, the operation log, and snapshots in S3 every few hundred operations.

Opening a document loads the latest snapshot plus the later operations and joins the session at that revision. The client applies its own edits immediately, sends them with the base revision, and reconciles with the server's order when other operations arrive. Cursors and presence go through the same session but are never stored.

I acknowledge only after the operation is durable, and clients keep unacknowledged operations and resend them with an id so duplicates are ignored. Permissions are checked on join and on every operation, and the log gives me history, restore and audit.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Design the main components, API and data model of a collaborative document editor for...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/56689b11e0/