How Notion handles concurrent editing with CRDTs
Notion, the popular collaborative workspace, allows multiple users to work on the same document simultaneously. However, prior to 2025, the platform struggled with seamless collaboration, as concurrent edits could lead to data loss and conflicts. To address these issues, Notion redesigned its underlying system and data model for text editing, implementing a Conflict-free Replicated Data Type (CRDT) to handle rich-text editing across blocks.
In a CRDT-based system, multiple clients maintain local copies of the same data and merge simultaneous changes deterministically. This ensures that concurrent edits can be merged without losing anyone's changes. While CRDTs prevent data loss, they may not always preserve the exact intent of each collaborator. For instance, if Emma intended to write "Build cool things," the merged result may not meet that goal.
Notion's chosen CRDT is a variant of the Replicated Growable Array (RGA), a tree data structure that stores all inserted characters as nodes with unique, stable IDs. Operations to insert or delete text reference these IDs, known as "text items" or "origins." The tree begins with start and end items.
For example, if Emma inserts "cool" after origin A@6 and Charlie inserts "quickly" at the same location, the resulting CRDT tree would be constructed as follows:
1. Emma's insert operation places "c" after origin A@6.
2. Charlie's insert operation places "quickly" after origin A@6.
3. A deletion operation marks the inserted characters as removed, storing them as "tombstones" to preserve their IDs for in-flight or offline operations.
Items in the CRDT tree are sorted by their logical timestamp, a Lamport clock value, and session ID. This ensures that operations with more recent timestamps are applied first, resolving conflicts.
To enhance storage efficiency, characters are grouped into runs with contiguous IDs and lengths. For instance, the deletion of "cool" can be simplified in the CRDT tree.
Notion's rich-text formatting, such as bold and italics, requires resolving conflicts between text edits and rich-text annotations. The Peritext algorithm is used to support these annotations, with operations to add and remove annotations based on text items' IDs. Bold annotations, for example, are extendable, meaning new text added after the bolded section will also be bolded.
In summary, Notion's adoption of CRDTs has enabled seamless collaboration by allowing concurrent edits to be merged without losing changes. While CRDTs prevent data loss, they may not always preserve the exact intent of collaborators. Notion addresses this by using Peritext to handle rich-text annotations, ensuring that the final document maintains the intended formatting.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.