dilshan.dev
Systems2023

CRDT Sync Engine

Conflict-free replicated data type engine for real-time state.

Convergence Latency< 15ms
Delta Compression70% Binary
Conflict Rate0% Mathematical
Max Concurrent Peers250+ / room

System Overview & Motivation

CRDT Sync Engine is a robust, mathematically proven replication library implementing YATA and fractional indexing algorithms for peer-to-peer real-time collaborative applications. It guarantees strong eventual consistency across offline-first clients with zero merge conflicts.

Key Architectural Highlights

  • Implements state-based RGA and LWW-Element-Set CRDT data structures
  • Compact binary state vector encoding reducing network synchronization bandwidth by 70%
  • Deterministic convergence under arbitrary network partitions and out-of-order delivery
  • WebSocket and WebRTC data channel transport adapters for peer-to-peer mesh sync
  • Zero external runtime dependencies with high-concurrency benchmarks

Technical Architecture & Data Pipeline

Document mutations are recorded as causal item structs with Lamport timestamps and client IDs. When peers connect, they exchange compact state vectors to compute diffs, merging incoming operations into local trees without central locking.

Production Challenges & Edge Cases Solved

Garbage collection of deletion tombstones without breaking causal history. Solved by implementing state vector snapshot compaction during quiescence periods.

Technology Stack & Dependencies

Algorithm

RGA CRDTLamport TimestampsYATA Algorithm

Encoding

TypeScriptUint8ArrayVarint Encoding

Transport

WebSocketsWebRTC Data Channels