Skip to the page

Collaboration and heavy clients · senior

Case study: collaborative editor (Google Docs)

A strong collaborative-editor design uses a structured document model, sends small operations instead of the whole document, resolves concurrent edits with OT (a central server transforms operations) or a CRDT such as Yjs (merges in any order, good offline), and keeps cursors and presence on a separate ephemeral channel.

The notes

What you must know

  • Document model: a structured tree (paragraphs, marks) via ProseMirror, Lexical, Slate or Tiptap, not raw contentEditable HTML.
  • Operations: insert, delete, format; batch keystrokes into small ops sent every ~50–100 ms; never send the full document per keystroke.
  • OT (Google Docs style): a central server orders operations and transforms concurrent ones against each other so every client converges; simpler storage, needs the server online.
  • CRDT (Yjs, Automerge): every character/element has a unique id so updates merge in any order with no central authority; great for offline and peer-to-peer; costs memory (tombstones) and complexity. Yjs says it 'doesn't need a central source of truth' and has bindings for ProseMirror, Tiptap, Monaco, CodeMirror and Quill.
  • Figma is a useful contrast: not true CRDTs; the server orders events and each object property is last-writer-wins, which is fine for shapes but would lose concurrent text edits.
  • Presence (cursors, selections, names) goes on an ephemeral 'awareness' channel, throttled, never into the document history.
  • Persistence and offline: an operation log plus periodic snapshots, version history and an autosave indicator ('Saving…', 'Saved'); queue local ops offline and on reconnect send them (CRDT) or rebase them (OT). Figma reconnects by downloading a fresh copy and re-applying offline edits.
  • Undo/redo per user (undo only your own operations); comments anchored to relative positions that survive edits; permission checks per operation on the server; block-level virtualisation for very long documents.

The red pen

Common traps: mistake → fix

  • Mistake: Send the whole document on each change and keep the last one

    Fix: concurrent edits are lost.

  • Mistake: Last-writer-wins on the whole document

    Fix: one user's typing erases the other's.

  • Mistake: Store cursor positions in the document history

    Fix: history and storage explode.

  • Mistake: A global undo stack

    Fix: undoing another person's edit.

Easy to hard

Questions interviewers ask, easy to hard

  1. Design the frontend of a Google Docs-like editor.
  2. Two users insert text at the same position at the same time. What happens?
  3. OT or CRDT? When would you choose each?
  4. A user edits offline for an hour. What happens on reconnect?
  5. How do you show 50 people's cursors without overloading the network?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview