ADR-08: Yjs CRDT for real-time collaborationΒΆ
ContextΒΆ
TINO needs concurrent multi-user editing of the same file without conflicts. The classic approaches are operational transformation (OT) β used by Google Docs β or conflict-free replicated data types (CRDTs). A third option was to skip real-time collaboration entirely and rely on git merges.
DecisionΒΆ
TINO uses Yjs (a CRDT library) with a custom WebSocket server backed by pycrdt (the Python
Yjs binding).
CodeMirror 6βs y-codemirror.next binding connects the editor state to the shared Yjs document.
Each open file gets a room on the server.
The server holds the authoritative document state in memory and syncs it to all connected clients.
Rooms are evicted after a configurable TTL (TINO_ROOM_TTL) of inactivity.
ConsequencesΒΆ
PositiveΒΆ
- Conflict-free mergesMerges are automatic and instantaneous β no conflict dialogs, ever.
- Resilient to disconnectsWorks correctly with intermittent connectivity; clients re-sync seamlessly on reconnect.
- Awareness for freeCollaborator cursors and presence (name, colour) come via the Yjs awareness protocol at no extra cost.
- Battle-testedThe CRDT model is well-studied and Yjs is widely deployed in production.
NegativeΒΆ
- In-memory stateThe server holds live document state for each active room β memory usage scales with the number of concurrently open files.
- Lost on restartIn-memory state is discarded on server restart; clients resync from the last saved file, losing any unsaved CRDT history.
- Native dependency
pycrdtis a native extension that may complicate some deployment environments.