Productivity & collaboration · Advanced

Google Docs collaborative editing

Operational transformation on one owning server per document, with an op log and snapshots.

Every part, and why it is there

Editors (browser)

Several people type into the same document at once. Each keystroke is applied locally first so typing never waits on the network, then sent as a small operation such as “insert ‘a’ at position 42”.

Load balancer

Routes the editing channel for a document to whichever collaboration server owns that document, and ordinary page loads to the docs API.

Collaboration servers

Exactly one server owns each open document. POST /docs/:id/ops receives an operation, transforms it against any operations it has not seen, appends it to the log and broadcasts it. Having one owner gives every edit a single agreed order without distributed locking.

Document ownership leases

Records which server currently owns which document, with a time-limited lease. If that server dies the lease expires and another server takes over by replaying the log.

Cursors & presence

Who is viewing and where each person’s cursor and selection are. Changes many times a second and is worthless after the session, so it lives in memory only.

Operation log

Every operation in order, keyed by document and revision number. This is the real document: any version can be rebuilt by replaying operations, which is also how revision history works.

Docs API

Opens, lists and shares documents. GET /docs/:id returns the latest snapshot plus the revision number to continue from.

Doc metadata & ACLs

Titles, owners, sharing settings and folder placement. Checked whenever someone opens a document or joins an editing session.

Document-changed events

Emitted every so often while a document is being edited. Snapshotting and search indexing both consume it, independently.

Snapshot writer

Replays recent operations onto the last snapshot and stores the result, so opening a long-lived document does not mean replaying years of keystrokes.

Snapshots

Full document state at a revision. Opening a document = latest snapshot + the few operations after it.

Search indexer

Updates the full-text index from the latest content. A few seconds behind the live document is fine for search.

Search index

Lets people find documents by words inside them, filtered by what they are allowed to see.

Asked in interviews at

  • amazon
  • meta
  • fountain
  • google

Learn more

All system design examples