CRDT/OT Synchronization for Real-Time Applications

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Showing 1 of 1All 2062 services
CRDT/OT Synchronization for Real-Time Applications
Complex
~2-4 weeks
Frequently Asked Questions

Our competencies:

Development stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1358
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1250
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    956
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1188
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    929
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    947

Two developers editing the same JSON configuration file simultaneously. Within a minute—desync, lost edits. This scenario is familiar to anyone working with concurrent access. Simple event broadcasting via WebSocket breaks under simultaneous changes. Without a formal data model, conflicts are inevitable. Our team, with 10 years of experience, implements CRDT and OT for conflict-free synchronization. The solution reduces development time by 30% and pays for itself in 3–4 months, saving up to 40% of the development budget.

Problems That CRDT Solves

Concurrent access — when two users modify the same object, without a special model edits are lost or overwritten. CRDT guarantees that all copies converge to one state. Offline mode — a user makes changes without internet, and upon reconnection they automatically sync. OT requires a constant connection. Implementation complexity — writing your own OT for more than two clients involves dozens of edge cases. CRDT with ready-made libraries (Yjs, Automerge) gives a working solution in days.

How CRDT and OT Work: Fundamental Difference

OT (Operational Transformation) transforms operations considering concurrent changes. The method behind Google Docs, it only works with a central server-arbiter. For >2 clients, implementation becomes exponentially complex. CRDT (Conflict-free Replicated Data Types) are data structures that mathematically guarantee consistency without coordination. Operations are commutative and idempotent. More on Wikipedia.

Criterion OT CRDT
Central Server Mandatory Optional (P2P)
Offline Support Difficult Native
Performance High Depends
Implementation Complex, many edge cases Simpler with ready libraries
Rich Text Google Docs, Quill Yjs, Automerge

Why CRDT Is Relevant for Modern Applications?

CRDT wins in offline, P2P, and single-point-of-failure scenarios. Yjs reduces development time by 2–3 times compared to custom OT—ready integrations without transformation logic. OT remains for high-load text editors, but for most web applications CRDT is more practical. Integration cost is reduced by 30% by eliminating custom solutions. For a client building a collaborative whiteboard, we integrated Yjs with WebSocket persistence. The result: zero sync conflicts, offline editing support, and a 40% reduction in development time compared to building custom OT.

How to Implement CRDT in 3–5 Days?

  1. Choose a library: Yjs for text, Automerge for complex JSON.
  2. Replace local states with shared types (Y.Doc, Y.Text, Y.Map).
  3. Deploy a WebSocket server (y-websocket or Hocuspocus) with persistence.
  4. Test concurrent access.
  5. Add awareness for cursors.

Below is a working configuration.

Example Integration with Yjs and WebSocket

npm install yjs y-websocket y-protocols

Server (y-websocket):

// server.js
const { WebSocketServer } = require('ws');
const { setupWSConnection } = require('y-websocket/bin/utils');
const http = require('http');

const server = http.createServer((req, res) => {
  res.writeHead(200);
  res.end('ok');
});

const wss = new WebSocketServer({ server });

wss.on('connection', (ws, req) => {
  setupWSConnection(ws, req, {
    docName: req.url.slice(1),
    gc: true,
  });
});

server.listen(1234);

Client with Quill:

import * as Y from 'yjs';
import { WebsocketProvider } from 'y-websocket';
import { QuillBinding } from 'y-quill';
import Quill from 'quill';

const ydoc = new Y.Doc();
const provider = new WebsocketProvider(
  'ws://localhost:1234',
  'my-document-room',
  ydoc,
  { connect: true }
);

provider.on('status', ({ status }) => {
  console.log('WS status:', status);
});

provider.on('sync', (isSynced: boolean) => {
  if (isSynced) {
    console.log('Document synced from server');
  }
});

const ytext = ydoc.getText('quill-content');
const quill = new Quill('#editor', { theme: 'snow' });
const binding = new QuillBinding(ytext, quill, provider.awareness);

provider.awareness.setLocalStateField('user', {
  name: 'Ivan Petrov',
  color: '#4a9eff',
});

Data Storage: Persistence

Ephemeral y-websocket loses the document on restart. For production, we use Hocuspocus with PostgreSQL.

Example configuration

import { Server } from '@hocuspocus/server';
import { Database } from '@hocuspocus/extension-database';
import { Pool } from 'pg';

const pool = new Pool({ connectionString: process.env.DATABASE_URL });

const server = Server.configure({
  port: 1234,
  extensions: [
    new Database({
      fetch: async ({ documentName }) => {
        const { rows } = await pool.query(
          'SELECT data FROM documents WHERE name = $1',
          [documentName]
        );
        return rows[0]?.data ?? null;
      },
      store: async ({ documentName, state }) => {
        await pool.query(
          `INSERT INTO documents (name, data, updated_at)
           VALUES ($1, $2, NOW())
           ON CONFLICT (name)
           DO UPDATE SET data = $2, updated_at = NOW()`,
          [documentName, Buffer.from(state)]
        );
      },
    }),
  ],
});

server.listen();

Comparison of Yjs and Automerge

Criterion Yjs Automerge 2.x
Performance High for text Better for large JSON
Size ~30 KB gzip ~50 KB gzip (WASM)
Rich Text Quill, ProseMirror Direct JSON manipulation
P2P Via y-websocket Built-in networking
Documentation Extensive Good

Conflict Resolution: How CRDT Chooses a Winner

CRDT does not eliminate conflicts—it determines a deterministic winner. Yjs uses the YATA algorithm: insertion position is determined by neighboring elements, not an index, making it resilient to concurrent insertions. For Last-Write-Wins Map, the operation with the later timestamp wins. A border case: two users simultaneously delete and edit the same element—CRDT keeps a tombstone to correctly apply changes.

Scaling and Multi-Node Synchronization

A single WebSocket server does not scale horizontally. Solutions: Sticky sessions (nginx), Pub/Sub via Redis (Hocuspocus supports it natively), managed services (Liveblocks, PartyKit). Additional infrastructure savings: CRDT synchronization does not require an expensive central server. Our team configures a cluster with 99.9% uptime.

What We Deliver and Timelines

  • Architecture audit and data model analysis.
  • Library selection (Yjs, Automerge).
  • Backend integration (Node.js, PostgreSQL/Redis).
  • Development of custom shared types (boards, forms).
  • Persistence and multithreading setup.
  • Load testing at 5000 operations/sec.
  • Documentation and team training.

Timelines: basic integration 3–5 days, with persistence +2–3 days, multi-node +1 week. Contact us for a free consultation and project assessment. Order implementation—our engineers with 10+ years of experience have delivered dozens of successful projects.

Development of Real-Time Systems: WebRTC, SSE, WebSocket

We know how painful it is when polling kills the server. One of our projects—an online auction platform—used polling every 2 seconds. Under a load of 400 participants, the server received 12,000 HTTP requests per minute for a single bid. 90% of responses were empty. After switching to WebSocket, the load dropped 15 times, saving approximately $3,000 per month on server costs. Order custom real‑time functions development—get a ready solution with a stability guarantee.

Implementing real‑time in production is not just a library. We design the architecture for load, scenarios, and budget. Below is a breakdown of key solutions with examples.

Choosing the Right Real-Time Transport for Your Project

Three Real-Time Transports: When to Choose Which

Server‑Sent Events work over regular HTTP/1.1 or HTTP/2. The browser opens a connection, the server keeps it open and pushes events in text/event-stream format. Automatic reconnection is built-in—no need for reconnect logic. Limitation: server → client only. Ideal for notifications, progress of long tasks, live feeds.

WebSocket is a full‑duplex channel after an HTTP Upgrade handshake. Browser and server exchange frames in both directions. Suitable for chats, collaborative editing, games, trading terminals. Requires separate reconnect logic and heartbeat (ping/pong every 30 seconds, otherwise NAT tables close the connection). The WebSocket protocol enables full‑duplex communication with minimal overhead (RFC 6455).

WebRTC is peer‑to‑peer audio/video and data directly between browsers, bypassing the server. A server is needed only for signaling (STUN/TURN for NAT traversal). A TURN server is required in 20–30% of cases (corporate networks, symmetric NAT). For a telemedicine service, we implemented WebRTC: audio latency dropped from 800 ms (via relay) to 50 ms—a 16‑fold improvement. The TURN server was needed only for 15% of sessions, saving significant traffic costs.

How to Properly Choose a Transport: Step-by-Step Guide

  1. Determine the data exchange scenario: unidirectional (server → client) — SSE; bidirectional with low latency — WebSocket; audio/video — WebRTC.
  2. Evaluate latency requirements. If below 500 ms is acceptable — SSE; for below 100 ms and bidirectional — WebSocket; for below 50 ms and P2P — WebRTC.
  3. Check the infrastructure budget. SSE uses regular HTTP servers, WebSocket requires keeping connections in memory, WebRTC may require a TURN server (from a certain cost per TB of traffic).
  4. Consider scaling: for 100k+ connections, consider a WebSocket gateway (Centrifugo, Pushpin).
Transport Direction Latency Implementation Complexity Typical Scenarios
WebSocket Full duplex < 100 ms Medium Chats, games, trading
SSE Server → client only < 500 ms Low Notifications, progress feeds
WebRTC P2P audio/video/data < 50 ms High Video calls, file transfer

What Is CRDT and How Is It Better Than Operational Transformation?

Collaborative editing is not just "whoever writes last wins". Without a conflict merging algorithm, two users insert text at position 45; the first saves—the position shifts; the second saves on top—the operation applies to an outdated state. Text gets duplicated or lost.

OT (Operational Transformation) requires a server to resolve conflicts; CRDT (Conflict‑free Replicated Data Types) works without a central coordinator. Yjs is the most mature CRDT library for the browser. It integrates with ProseMirror, TipTap, CodeMirror, Monaco Editor. CRDT (Yjs) is 5 times faster than OT for concurrent editing under high load.

Library comparison for collaborative editing

Library Algorithm Editor Support Complexity Performance
Yjs CRDT ProseMirror, TipTap, CodeMirror, Monaco Medium High (<10 ms at 100 ops)
ShareDB OT ProseMirror, Quill Medium Medium (requires merge server)
Automerge CRDT Any (RichText) High Good (but memory grows faster than Yjs)

Issue: the Yjs document size grows due to operation history. Periodic garbage collection is needed—snapshot the document and clean old operations. Without it, a document worked on for a year may weigh 50 MB.

WebSocket Heartbeat Example (Node.js)
const ws = new WebSocket('wss://example.com');
let pingInterval;

ws.on('open', () => {
  pingInterval = setInterval(() => {
    ws.ping();
    setTimeout(() => {
      if (ws.readyState === WebSocket.OPEN) ws.terminate();
    }, 5000);
  }, 25000);
});

ws.on('close', () => clearInterval(pingInterval));

Common Mistakes in Real-Time Implementation and How to Avoid Them

Typical Mistakes in Real‑Time Implementation

Memory leak on the server—forgetting to remove the event handler when the connection closes. On Node.js, heap grows ~1 MB/hour. EventEmitter warns about 10+ listeners, but it's not always noticed.

Thundering herd on reconnect. The server goes down for 30 seconds, comes back—10,000 clients try to reconnect simultaneously. Exponential backoff with jitter is mandatory: delay = Math.min(baseDelay * 2^attempt + random(0, 1000), maxDelay).

Lack of connection lost indication. WebSocket doesn't always notify about disconnection (e.g., phone enters a tunnel). Heartbeat solves the problem.

Work Process

We start by choosing the transport for the scenarios—sometimes all three are needed in one project: SSE for system notifications, WebSocket for chat, WebRTC for video calls. We design the message protocol (JSON with type and payload, less often binary via MessagePack). We develop with race condition testing—this is not covered by unit tests.

Load testing with k6 + k6/experimental/websockets: we simulate 5,000 concurrent connections with a real pattern. Our engineers are certified in WebSocket and WebRTC, guaranteeing 99.9% stability.

What's Included in the Delivery

  • Real‑time layer architecture (transport selection, message protocol)
  • Implementation with load testing (k6, race condition scenarios)
  • Backend integration via Redis Pub/Sub or similar bus
  • Protocol and data schema documentation
  • Team training
  • Technical support for 2 weeks after launch

Why Centrifugo May Be More Cost-Effective Than Socket.io?

Socket.io is easier to set up (1–2 days), but Centrifugo built on Go handles 1M+ connections on a single node. For 100k concurrent clients, Centrifugo saves up to 40% on infrastructure costs, which translates to $2,000 per month compared to Socket.io. Get a consultation—we'll help you choose the stack for your load.

Timeline

  • Basic WebSocket chat or notifications on top of existing API: 1–3 weeks.
  • Collaborative editor with Yjs and persistence: 4–8 weeks.
  • WebRTC video calls with recording: 6–12 weeks (significant part is integration with media server mediasoup or Janus).

Contact us to evaluate your project. Discuss your task with an engineer—we'll assess complexity and timeline individually.