Chapter 03 // Real-World Frameworks

Production Protocols & Sync Frameworks

Building a robust local-first application no longer requires inventing custom CRDT math from scratch. The open-source ecosystem provides battle-tested engines tailored for document collaboration, relational sync, or hybrid transactional caches.

The Four Dominant Paradigm Stacks

Selecting the appropriate engine depends primarily on your application's data model: collaborative text, arbitrary JSON documents, or relational SQL tables.

ENGINE // 01

Yjs (High-Performance Shared Types)

An ultra-fast CRDT implementation written in JavaScript with compact binary encoding. It uses the YATA algorithm to structure text, maps, and arrays, making it the industry standard for rich-text editors (ProseMirror, Quill, Monaco, Slate).

  • • Best For: Collaborative documents, canvas tools, code editors
  • • Memory: Exceptionally lean itemized linked list structure
  • • Ecosystem: Complete bindings for WebRTC, WebSocket, IndexedDB

ENGINE // 02

Automerge (Rust Core + Document Trees)

A JSON-like CRDT data structure featuring a high-performance Rust core compiled to WebAssembly. Automerge stores an immutable version history, enabling Git-like branching, time-travel scrubbing, and verifiable cryptographic commit logs.

  • • Best For: Versioned state, offline journals, branching documents
  • • Compression: Columnar chunk format reduces sync payloads by 90%
  • • Integrity: SHA-256 commit hashes verify edit provenance

ENGINE // 03

ElectricSQL (Postgres-to-SQLite Sync)

A replication engine that captures changes from central PostgreSQL via logical replication streams and syncs them bi-directionally to client-side SQLite instances using Shapes and Satellites.

  • • Best For: Complex multi-table relational applications, B2B SaaS
  • • Querying: Standard reactive SQL queries on the device
  • • Permissions: Row-level security enforced via Electric Shapes

ENGINE // 04

Replicache & PowerSync

Optimistic client-side caches that decouple mutation queuing from conflict resolution. Mutations run instantly against local IndexedDB or SQLite, enqueue to an outbox, and reconcile via server push streams.

  • • Best For: Existing backend stacks that cannot adopt CRDT math
  • • Simplicity: Allows custom server-side validation logic
  • • Tradeoff: Requires custom rebase replay handlers on divergence

Architectural Decision Matrix

Evaluate key engineering requirements against the capabilities of modern production engines.

Evaluation Criteria Yjs Automerge ElectricSQL PowerSync
Primary Data Model Collaborative Text & Maps JSON Document Trees Relational SQL Tables Relational SQLite Tables
Core Implementation JavaScript (Binary encoded) Rust (WASM Bindings) Elixir Core + TS / WASM C++ Core + Native Bindings
Conflict Resolution YATA sequence merging Op-based Tree CRDT Postgres-side transactional Last-Write-Wins / Custom
End-to-End Encryption Native over Y-WebRTC Native via document keys Requires custom payload cipher At-rest on client device
Historical Time Travel Snapshot states Full immutable git-like log Database WAL retention Custom event stream

End-to-End Encryption in Local-First Meshes

Because local-first systems execute all business rules and search indexing on the user's local hardware, central sync servers can be demoted to blind, zero-knowledge relays. When documents are symmetrically encrypted on device using XChaCha20-Poly1305 before transmission, data remains mathematically inaccessible to third-party infrastructure operators, surveillance sweeps, and unauthorized cloud tenants.