Operational Transform (OT) for real-time collaboration in mobile app

NOVASOLUTIONS.TECHNOLOGY is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Operational Transform (OT) for real-time collaboration in mobile app
Complex
from 2 weeks to 3 months
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1052
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Implementing Operational Transform (OT) for Real-time Collaboration in Mobile Applications

Operational Transform — algorithm powering Google Docs, Notion, Etherpad. Not abstraction, but concrete math: each document change — operation (insert(pos, text) or delete(pos, len)), which transforms relative to concurrent operations so all clients converge to one result.

Understanding OT important not only for from-scratch implementation but for conscious choice between OT and CRDT.

The Problem OT Solves

Two users edit document "hello":

  • User A: insert(5, " world") → "hello world"
  • User B simultaneously: delete(0, 5) → ""

Simply applying both operations in any order — results diverge. OT transforms A's operation accounting for B's:

  • transform(insert(5, " world"), delete(0, 5))insert(0, " world") (position shifts because 5 chars deleted before it)

Result: " world" — identical on both clients.

Server Architecture for OT

OT requires server-coordinator. Scheme:

Client A ──→ Server ──→ Client B
   ↑             │           │
   └─────────────┘           │
        ACK + revision       │
                             ↓
                   Client B transforms
                   its pending operations

Server maintains operation history with revision numbers. Client sends operation with base revision number (operation created from). Server transforms incoming operation relative to operations applied after that revision, applies, returns confirmation and broadcasts transformed operation to all.

Client stores:

  • revision — last confirmed revision from server
  • pending — sent but not confirmed operation
  • buffer — operations entered while pending not confirmed

On receiving server operation: if client has pending, mutually transform server operation and client via transform(client, server) and transform(server, client).

Transform Algorithm for Text

For text operations transformation — position adjustment:

transform(insert(p1, s1), insert(p2, s2)):
  if p1 < p2: return insert(p1, s1)  // position unchanged
  if p1 > p2: return insert(p1 + len(s2), s1)  // shift right
  if p1 == p2: return insert(p1, s1)  // tie-breaking by userId

transform(insert(p1, s1), delete(p2, len2)):
  if p1 <= p2: return insert(p1, s1)
  if p1 >= p2 + len2: return insert(p1 - len2, s1)
  else: return insert(p2, s1)  // insert was inside deleted range

For formatting (rich text) transformation more complex — operations on attributes have own semantics.

Libraries: ot.js, sharedb

ot.js — pure JavaScript OT engine for simple text type. Works in React Native without modifications. Implements compose and transform operations. Doesn't include transport.

ShareDB — full framework: OT engine + WebSocket server + client. Supports pluggable operation types (json0, rich-text, custom). json0 allows OT on JSON documents — useful for structured data (not just text).

ShareDB client for React Native:

import ReconnectingWebSocket from 'reconnecting-websocket';
import ShareDB from 'sharedb/lib/client';

const socket = new ReconnectingWebSocket('wss://server.com/sharedb');
const connection = new ShareDB.Connection(socket);
const doc = connection.get('documents', documentId);

doc.subscribe(() => {
  doc.on('op', (op, source) => {
    if (!source) {
      // remote operation — update UI
      applyOpToEditor(op);
    }
  });
});

ReconnectingWebSocket — critical for mobile: on network change (Wi-Fi → 4G) auto-reconnects and restores sync.

Composition: Multiple Operations Into One

Fast typing generates dozens of operations per second. Batching: ot.js supports compose(op1, op2) — merge consecutive operations. Send compose-operation every 50–100ms instead of each separate.

Condition for compose: operations must be sequential (op2 applies after op1). If server operation arrives between op1 and op2 — compose impossible, transform separately.

OT vs CRDT: What to Choose By

Criterion OT CRDT
Offline mode Limited Native
Server Mandatory Optional
Client complexity Medium Higher
Server complexity Higher Lower
Library maturity ShareDB — production-ready Y.js — production-ready
Rich text support rich-text OT type Y.Text with attributes

Choose OT when: strict operation history needed, server-coordinator already exists, offline not required. CRDT — when offline mode important and P2P sync.

Assessment

ShareDB integration for text editor on React Native — 6–10 weeks (including server part). If need JSON-document OT (structured data) — 10–16 weeks. Implementing OT from scratch without ShareDB — not recommended: transform algorithm has edge cases hard to test.