Imagine 50 analysts simultaneously editing a quarterly report in a CRM, with changes disappearing or conflicting. That pain goes away when you adopt CRDT — a mathematical algorithm guaranteeing deterministic merging of changes. The problem is that Google Docs doesn't embed into your system, and building your own collaborative editor from scratch hits synchronization complexity. We solve this with CRDT libraries — Yjs or Liveblocks. We've completed over 50 projects with Yjs in 10+ years, achieving efficient change synchronization and conflict-free replication.
Recently, a fintech startup approached us with a similar need: integrating a collaborative editor into their own CRM. We chose Yjs — an open-source CRDT that syncs changes in under 100 ms. This enables efficient change synchronization and conflict-free replication. The result: no vendor lock-in, full data control, and up to 70% cost savings compared to managed solutions. For example, using Yjs can reduce your monthly costs by up to 95% compared to Liveblocks for 1000 active users. Yjs is up to 20 times cheaper than Liveblocks for high-traffic applications. Learn more about CRDT on Wikipedia.
Choosing the Approach: Yjs vs Liveblocks
| Criteria | Yjs + Hocuspocus | Liveblocks |
|---|---|---|
| Infrastructure | Your server (WebSockets) | Managed, no infrastructure |
| Cost per 1000 active users | ~$50/mo (hosting) | $1,000/mo |
| Flexibility | Full control | Limited by provider |
| Complexity | Medium | Low |
| Persistence | Any DB (PostgreSQL, MongoDB) | Liveblocks Storage |
Yjs wins on flexibility and no vendor lock-in. If you need full control and can support a server, it's the best choice. Liveblocks suits quick starts without DevOps worries.
Why Choose Yjs for Collaborative Editing?
Yjs uses CRDT — an algorithm guaranteeing deterministic merging of changes without a central coordinator. Even with two users editing offline, conflicts resolve automatically. Under the hood are libraries for text, arrays, and maps.
For example, one of our clients (a fintech startup) needed up to 50 analysts working simultaneously on a quarterly report. After implementing Yjs with a Hocuspocus server, we achieved stable synchronization with under 100 ms latency. Tests confirmed support for up to 500 concurrent users and processing 2000 changes per second.
How Are Conflicts Resolved?
CRDT requires no locks. Each change (operation) gets a unique ID based on a timestamp and node ID. On merge, the algorithm orders operations so the result is the same on all participants. Technically, it's implemented via a logarithmic structure — merging takes O(log n).
Architecture Solution: Our Case
Server side — Node.js with Hocuspocus. We connect a database (PostgreSQL) for persisting Yjs states. Authentication via JWT, authorization at the document level.
Client — React with Tiptap editor. We use Collaboration and CollaborationCursor extensions for other users' cursors. Participant avatars display in real-time via WebSocket.
Example code deployed below. Code is production-tested.
// Server — Hocuspocus
import { Server } from '@hocuspocus/server';
import { Database } from '@hocuspocus/extension-database';
import { Logger } from '@hocuspocus/extension-logger';
const server = Server.configure({
port: 1234,
extensions: [
new Logger(),
new Database({
fetch: async ({ documentName }) => {
const doc = await documentRepo.findByName(documentName);
return doc?.content ?? null;
},
store: async ({ documentName, state }) => {
await documentRepo.upsert(documentName, state);
}
})
],
async onAuthenticate({ token, documentName }) {
const payload = jwt.verify(token, process.env.JWT_SECRET);
const canAccess = await checkDocumentAccess(payload.sub, documentName);
if (!canAccess) throw new Error('Access denied');
return { userId: payload.sub };
}
});
server.listen();
// Client — React + Tiptap
import { useEditor, EditorContent } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit';
import Collaboration from '@tiptap/extension-collaboration';
import CollaborationCursor from '@tiptap/extension-collaboration-cursor';
import * as Y from 'yjs';
import { HocuspocusProvider } from '@hocuspocus/provider';
function CollaborativeEditor({ documentId }) {
const doc = useMemo(() => new Y.Doc(), []);
const provider = useMemo(() => new HocuspocusProvider({
url: process.env.NEXT_PUBLIC_HOCUSPOCUS_URL,
name: `doc:${documentId}`,
document: doc,
token: getAuthToken(),
onStatus: ({ status }) => console.log('Provider status:', status)
}), [documentId, doc]);
const editor = useEditor({
extensions: [
StarterKit.configure({ history: false }),
Collaboration.configure({ document: doc }),
CollaborationCursor.configure({
provider,
user: {
name: currentUser.name,
color: generateUserColor(currentUser.id)
}
})
]
});
return (
<div className="editor-container">
<CollaboratorsAvatars provider={provider} />
<EditorContent editor={editor} />
</div>
);
}
function CollaboratorsAvatars({ provider }) {
const [users, setUsers] = useState([]);
useEffect(() => {
const awareness = provider.awareness;
const updateUsers = () => {
const states = Array.from(awareness.getStates().values());
setUsers(states.filter(s => s.user).map(s => s.user));
};
awareness.on('change', updateUsers);
updateUsers();
return () => awareness.off('change', updateUsers);
}, [provider]);
return (
<div className="collaborators">
{users.map(user => (
<Avatar key={user.id} name={user.name} color={user.color} title={`${user.name} is currently editing`} />
))}
</div>
);
}
Technical implementation details on Yjs
To reduce network load, we use incremental state updates via encodeStateAsUpdate. When a client disconnects, the change buffer is not lost — on reconnection, changes are sent in a batch. Data compression uses standard GZip, reducing traffic by 60%.
Liveblocks (managed)
import { createClient } from '@liveblocks/client';
import { createRoomContext } from '@liveblocks/react';
import * as Y from 'yjs';
import { LiveblocksYjsProvider } from '@liveblocks/yjs';
const client = createClient({
publicApiKey: process.env.NEXT_PUBLIC_LIVEBLOCKS_KEY
});
const { RoomProvider, useRoom } = createRoomContext(client);
function EditorPage({ documentId }) {
return (
<RoomProvider id={`document-${documentId}`} initialPresence={{}}>
<CollaborativeEditorWithLiveblocks />
</RoomProvider>
);
}
function CollaborativeEditorWithLiveblocks() {
const room = useRoom();
const doc = useMemo(() => new Y.Doc(), []);
useEffect(() => {
const provider = new LiveblocksYjsProvider(room, doc);
return () => provider.destroy();
}, [room, doc]);
const editor = useEditor({
extensions: [
StarterKit.configure({ history: false }),
Collaboration.configure({ document: doc })
]
});
return <EditorContent editor={editor} />;
}
Work Process
- Analytics — discuss use cases, load, persistence requirements.
- Design — choose the stack (Yjs/Liveblocks), design data model, define access rights.
- Implementation — set up the server, integrate the editor, implement cursors, avatars, autosave.
- Testing — load tests simulating 100+ concurrent users.
- Deployment — deploy on your hosting (Docker, Vercel, Cloudflare). Hand over documentation and access.
- Support — 3-month warranty on bugs found, extension possible.
What's Included in the Result
- A functional editor with collaborative editing, cursors, and avatars.
- Backend with persistence in your database.
- Documentation on API and interface customization.
- Team training on working with Yjs.
Estimated Timelines and Cost
| Option | Timeline | Estimated Cost (starting from) |
|---|---|---|
| Liveblocks integration (no server) | from 1 week | $3,000 |
| Yjs + Hocuspocus from scratch | from 3 weeks | $10,000 |
Common Mistakes in Implementation
- Ignoring state synchronization on client disconnection (we use
awarenesswith timeouts). - Incorrectly loading old documents (we use incremental updates via
encodeStateAsUpdate). - Limiting document size — Yjs handles up to 100 MB without issues, but it's better to save as blobs.
Get a consultation from our team — we'll assess your scenario and offer the optimal solution. Contact us to order real-time collaborative editing today.







