ElectricSQL: Local-First SQL Sync with Elixir
Local-first is the end game of state transfer: your app talks to a local SQL database, data syncs in the background via CRDTs, and you get instant UX + real-time collaboration + offline support as system primitives instead of application concerns.
Read Original Summary used for search
TLDR
• ElectricSQL syncs Postgres to SQLite in browsers/devices using Elixir, giving you active-active replication with automatic conflict resolution—write to local DB, changes propagate everywhere instantly
• Shape-based replication lets frontend devs declaratively control what data syncs (whole tables, filtered rows, association graphs) without backend changes—no more writing REST/GraphQL queries
• Implements transactional causal+ consistency using CRDTs with "rich CRDT techniques" (compensations for referential integrity, reservations for distributed locking) to maintain SQL invariants in an AP system
• Postgres becomes a control plane: schema migrations auto-stream to clients, you publish content by writing to Postgres, business logic moves to database rules/event sourcing
• Trade-off: you lose the traditional backend and deal with eventual consistency, but gain Figma/Linear-grade UX (instant + real-time + offline) as a development primitive
In Detail
ElectricSQL positions local-first as the natural evolution of state transfer—moving from imperative network calls (forms→Ajax→REST→GraphQL) to a fully declarative system where applications talk to local embedded databases and sync happens in the background. The core thesis is that by moving state transfer out of application code into the system layer, you can optimize a broader range of concerns (consistency, availability, resource usage) automatically, similar to how GraphQL's relay compiler optimizes data fetching but extended to the entire data lifecycle.
The system provides a "Brownfield strategy" for existing Postgres applications: drop ElectricSQL on as a sync layer and get instant local-first APIs. It implements active-active replication between Postgres and SQLite (in browsers/mobile), with Postgres acting as a control plane—schema migrations automatically stream to clients, you can publish content by writing to Postgres, and optionally aggregate data back from devices. The demo shows a Phoenix app syncing GitHub stars to a React app in real-time, with offline tolerance and automatic conflict resolution. Frontend code just writes to the local SQLite database using a typesafe client (auto-generated from Postgres schema), and changes propagate everywhere instantly.
The key innovation is shape-based replication: frontend developers declaratively specify what subset of data to sync (whole database, specific tables, filtered rows, association graphs) without backend coordination. This enables strategies from whole-DB sync to ephemeral queries, with the system handling partial replication boundaries. Under the hood, it implements transactional causal+ consistency using CRDTs, with "rich CRDT techniques" like compensations (for referential integrity) and reservations (distributed locking for unique constraints) to maintain SQL invariants in an eventually consistent system. The trade-offs are real: you lose the traditional backend (business logic moves to frontend/database rules/event sourcing), face authorization challenges with partial replication, and must design for eventual consistency. But you gain instant reactivity, real-time multi-user collaboration, and offline support as system primitives—the combination needed to build Figma/Linear-grade UX without custom infrastructure.