Introduction
Yjs is a high-performance CRDT (Conflict-free Replicated Data Type) framework written in JavaScript. It allows multiple users to edit the same data concurrently without conflicts. Yjs is editor-agnostic and works with Tiptap, ProseMirror, Monaco, CodeMirror, Quill, and many other editors.
What Yjs Does
- Merges concurrent edits automatically without a central server
- Provides shared data types: Text, Array, Map, and XML Fragment
- Syncs state over WebSocket, WebRTC, or any custom transport
- Supports offline editing with automatic reconciliation on reconnect
- Tracks awareness (cursor positions, user presence) across peers
Architecture Overview
Yjs represents shared state as a document (Y.Doc) containing typed structures. Each edit is encoded as an update operation that can be applied in any order. The CRDT algorithm ensures all peers converge to the same state regardless of message ordering. Providers handle transport: y-websocket for client-server, y-webrtc for peer-to-peer, and y-indexeddb for local persistence.
Self-Hosting & Configuration
- Install
yjsand a provider (y-websocket,y-webrtc, ory-indexeddb) - Run the y-websocket server:
HOST=localhost PORT=1234 npx y-websocket - Bind shared types to your editor using bindings (e.g.,
y-prosemirror,y-monaco) - Persist documents server-side with LevelDB or a custom storage adapter
- Scale horizontally by partitioning documents across WebSocket server instances
Key Features
- Sub-millisecond merge performance even with large documents
- Works offline-first with sync on reconnect
- Awareness protocol for live cursors and user presence
- Undo/redo manager with per-user scope
- Sub-document support for lazy loading parts of a large document
Comparison with Similar Tools
- Automerge — Rust-based CRDT, better for structured data; Yjs is faster for text
- ShareDB — OT-based, requires a central server; Yjs is decentralized
- Liveblocks — managed service with CRDT under the hood; Yjs is self-hostable
- Fluid Framework — Microsoft-backed, more opinionated architecture
- Gun.js — decentralized database with eventual consistency, different use case
FAQ
Q: Which editors does Yjs support? A: Tiptap, ProseMirror, CodeMirror, Monaco, Quill, Slate, Lexical, and others via official or community bindings.
Q: Can Yjs work without a server?
A: Yes, use y-webrtc for peer-to-peer sync or y-indexeddb for local-only persistence.
Q: How does conflict resolution work? A: Yjs uses CRDTs, so all concurrent edits are merged deterministically. No conflicts require manual resolution.
Q: How large can documents get? A: Yjs handles documents with millions of operations efficiently through incremental encoding and garbage collection.