·

System Design Deep Dive - 10 How Notion Handles Collaborative Editing

Post by ailswan May. 26, 2026

中文 ↓

🎯 How Notion Handles Collaborative Editing


1️⃣ Core Collaboration Framework (Staff-Level)

When discussing a Notion-like collaborative editor, I frame it as:

  1. Local-first editing
  2. Operation log
  3. Conflict resolution
  4. Server sequencing
  5. Presence and cursors
  6. Snapshots and compaction
  7. Offline and reconnect recovery
  8. Trade-offs: responsiveness vs convergence vs complexity

2️⃣ Core Problem

Multiple users can edit the same document at the same time.

The system must provide:


👉 Interview Answer

A Notion-like editor should feel local but converge globally. The client applies edits immediately, sends operations to the server, and the system merges concurrent operations into a shared document state.


3️⃣ High-Level Architecture

Client Local Editor
        ↓
Operation Builder
        ↓
Sync Service
        ↓
Document Operation Log
        ↓
Conflict Resolver / Sequencer
        ↓
Snapshot Store
        ↓
Broadcast to Collaborators

4️⃣ Operation-Based Sync

Instead of sending the whole document, clients send operations:

insert block
delete block
update text
move block
change property

Each operation includes:


👉 Interview Answer

Operation sync is better than repeatedly sending full documents. It reduces bandwidth, enables history, and gives the system a way to merge concurrent edits.


5️⃣ Conflict Resolution

Common approaches:

For block-based documents, conflicts often involve:


👉 Interview Answer

The exact algorithm can be OT, CRDT, or a server-sequenced operation model. The important interview point is that concurrent operations must be transformed or merged so all clients converge to the same document state.


6️⃣ Snapshots and Compaction

Operation logs grow forever if not compacted.

Use:

Load path:

Load latest snapshot
  ↓
Replay recent operations
  ↓
Return current document

7️⃣ Presence

Presence includes:

Presence is ephemeral and should not be stored like durable document edits.


8️⃣ Offline and Reconnect

Client behavior:


9️⃣ Staff-Level Trade-offs

Decision Benefit Cost
Local-first editing Great UX More sync complexity
Operation log History and mergeability Needs compaction
CRDT-style merge Offline-friendly Higher metadata overhead
Server sequencing Easier authority More dependence on server
Presence over sockets Realtime collaboration Ephemeral scaling cost

中文部分

中文速记

一句话

Notion Collaborative Editing 的核心是 local-first editing + operation sync:本地先响应,后台同步并保证最终收敛。


背诵要点


中文面试回答

我会把 Notion 协作编辑设计成 local-first 的 operation-based sync。 用户输入时,客户端先在本地立即应用编辑,保证打字体验低延迟。 同时客户端生成 operation,比如 insert block、delete block、update text、move block,并带上 document ID、base version、operation ID 和 client ID 发给 sync service。

服务端负责给 operation 排序或做 merge,然后写入 document operation log,并广播给其他协作者。 对于并发编辑,可以使用 OT、CRDT 或 server-authoritative sequencing,关键是所有客户端最终要收敛到同一个文档状态。

Staff 级重点是:协作编辑的难点不是保存文档,而是在低延迟体验和一致收敛之间做平衡。 大文档还需要 snapshot 和 compaction,避免每次加载都 replay 全部历史操作。


✅ Final Interview Answer

A Notion-like collaborative editor uses local-first editing with operation-based synchronization. The client applies edits immediately, creates operations with base versions and operation IDs, and sends them to a sync service. The server sequences or merges operations, persists them in a document operation log, and broadcasts accepted changes to other clients.

To keep large documents efficient, the system periodically creates snapshots and only replays recent operations. Presence and cursors are handled separately as ephemeral realtime state. At staff level, the core trade-off is responsiveness versus convergence complexity: users want instant editing, but the system must still guarantee that all clients eventually see the same document.

Implement