Low Level Design: Operational Transform Sync

OT for Text

Operations are insert(pos, text) and delete(pos, len).

Transformation Function

transform(op1, op2) adjusts positions of concurrent ops to maintain convergence. Example: if op1 inserts before op2 position, op2 position shifts by op1.length.

Server Algorithm

Server serializes all ops; each client sends op with client_revision; server transforms against all ops since that revision.

Data Schema

Document Table

Document (
  id UUID,
  content TEXT,
  revision INT
)

Operation Table

Operation (
  id UUID,
  doc_id UUID,
  revision INT,
  type ENUM(insert, delete),
  position INT,
  text TEXT,       -- for insert
  length INT,      -- for delete
  client_id TEXT,
  created_at TIMESTAMP
)

Operation Flow

Client sends op
  → Server receives
  → Transform against ops since client_revision
  → Apply to document
  → Broadcast transformed op to other clients

Client receives server op
  → Transform against pending local ops
  → Apply

Diamond Problem

op1 and op2 concurrent: server applies op1, transforms op2 against op1, sends transformed op2 to client who sent op1; client transforms op2 against their pending ops.

Cursor Position Preservation

Cursor ops transformed alongside text ops to maintain correct cursor positions for all participants.

See also: Netflix Interview Guide 2026: Streaming Architecture, Recommendation Systems, and Engineering Excellence

See also: Atlassian Interview Guide

See also: Meta Interview Guide 2026: Facebook, Instagram, WhatsApp Engineering

Scroll to Top