The Shift to Local-First Software: How CRDTs and SQLite Are Replacing Centralized Clouds
The problem with cloud-first
Cloud apps gave us collaboration and multi-device access. They also made us tenants of our own data.
When the server is the primary copy, three things break:
- Offline doesn't work — no network means no app
- Speed of light limits latency — every keystroke hits a distant server
- Longevity is out of your hands — the service shuts down and your work disappears
The 2019 Ink & Switch manifesto called this out: we became borrowers of our own data. Local-first software flips the model. Your device holds the primary copy. Servers become sync assistants, not authorities.
What "local-first" actually means
Seven ideals from the manifesto:
| Ideal | What it looks like |
|---|---|
| No spinners | Reads/writes hit local disk, not network |
| Multi-device | Background sync across all your devices |
| Offline | Full read/write without internet |
| Collaboration | Real-time multi-user via CRDTs |
| Longevity | Data outlives the company that built the app |
| Privacy | Encrypted locally, server sees ciphertext |
| User control | Copy, modify, delete — no permission needed |
This isn't "offline-first" (which treats offline as a degraded mode). Local-first treats local as primary.
The stack that made this practical (2024–2025)
Three things matured at roughly the same time:
flowchart LR
A[SQLite everywhere] --> B[Local store]
C[CRDTs mature] --> D[Conflict-free merge]
E[Sync engines] --> F[Background replication]
B & D & F --> G[Local-first app]
1. SQLite runs everywhere now
- Native: iOS, Android, desktop — SQLite is built in
-
Browser:
wa-sqlite(WASM) + OPFS (Origin Private File System) = full SQLite in tabs - Server: libSQL (Turso fork) adds replication, HTTP access
No more IndexedDB workarounds. SQLite is the local database.
2. CRDTs solve the merge problem
CRDTs (Conflict-free Replicated Data Types) let independent replicas merge deterministically without coordination.
Two families:
- State-based (CvRDTs) — send full state, merge via mathematical join
- Operation-based (CmRDTs) — broadcast commutative operations
The main libraries:
- Automerge — JSON-like document model, Rust and JS bindings
- Yjs — high-performance shared types, powers Notion and Tiptap
- CR-SQLite — CRDTs inside SQLite as virtual tables
3. Sync engines handle the plumbing
| Engine | Model | Client DB | Best for |
|---|---|---|---|
| ElectricSQL | Read-only sync (Postgres → client) | In-memory Map | Dashboards, reference data |
| PowerSync | Bidirectional (Postgres/MySQL/Mongo → SQLite) | Full SQLite | Mobile-first, cross-platform |
| Replicache | Mutation push + rebase | IndexedDB KV | Highly interactive web (Linear-style) |
| Zero | Bidirectional, Postgres-backed | SQLite (WASM) | Full-stack React apps |
| LiveStore | Event-sourced + CRDTs | SQLite/IndexedDB | Real-time collaborative UX |
PowerSync has the broadest platform coverage — official SDKs for Flutter, React Native, Swift, Kotlin, and web. ElectricSQL is simplest if you only need read sync from Postgres. Replicache gives the most control over conflict resolution.
CR-SQLite: CRDTs as a SQLite extension
This is the practical path for teams already using SQLite.
-- Load the extension (once per connection)
SELECT load_extension('crsqlite');
-- Regular table
CREATE TABLE tasks (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
done INTEGER DEFAULT 0,
sort_order REAL -- fractional index for drag-drop
);
-- Convert to a Conflict-free Replicated Relation (CRR)
SELECT crsql_as_crr('tasks');
Now:
- Write offline on any device
- Changes merge automatically on sync
-
sort_orderuses fractional indexing CRDT — drag-drop works concurrently -
doneuses LWW (last-write-wins) CRDT
Delta sync is cell-level. Each cell has a logical clock. Sync sends only changed cells since last peer contact — not full database dumps.
-- See what changed since peer 'device-2' last synced
SELECT * FROM crsql_changes WHERE site_id = 'device-2' AND clock > 42;
Automerge 3.0: the memory breakthrough (2024)
Previous versions compressed history on disk but decompressed in memory. Large documents meant gigabytes of RAM.
Automerge 3.0 uses the columnar compression format in memory.
Pasting Moby Dick:
Automerge 2: 700 MB
Automerge 3: 1.3 MB (500x reduction)
Large history load time:
Before: 17 hours
After: 9 seconds
The API also cleaned up — collaborative text is now plain string:
import * as Automerge from '@automerge/automerge';
const doc = Automerge.init();
Automerge.updateText(doc, ['content'], (text) => {
text.splice(0, 0, 'Hello '); // Insert at position 0
});
No more Text class, no next namespace. Backwards compatible with v2 file format.
How to start today
Simplest path (web app, Postgres backend):
- Add ElectricSQL sync service (Docker container)
- Enable Postgres logical replication
- Stream "Shapes" (filtered table subsets) to client
- Query local in-memory Map — instant reads
// Client
import { ShapeStream, Shape } from '@electric-sql/client';
const stream = new ShapeStream({ url: '/v1/shape/active-tasks' });
const tasks = new Shape(stream);
await tasks.value; // Initial load
tasks.subscribe(data => render(data)); // Live updates
Full offline + mobile (React Native / Flutter):
- PowerSync backend service (connects to Postgres/MySQL/Mongo)
- Client SDK embeds SQLite
- Define Sync Rules (which tables, filters)
- Write normal SQL locally — sync is automatic
// PowerSync React Native
import { PowerSyncDatabase } from '@powersync/react-native';
const db = new PowerSyncDatabase({
database: new SQLiteDatabase('app.db'),
sync: new PowerSyncSyncEngine({
endpoint: 'https://sync.yourapp.com',
token: getAuthToken(),
}),
});
// Normal SQL, works offline
const tasks = await db.getAll(
'SELECT * FROM tasks WHERE project_id = ?', [projectId]
);
await db.execute('UPDATE tasks SET done = 1 WHERE id = ?', [taskId]);
Maximum control + CRDTs (custom merge logic):
- Use CR-SQLite extension directly
- Define CRDT type per column (LWW, Counter, Fractional Index, Peritext)
- Handle sync yourself (WebRTC, central relay, QR codes — any transport)
Trade-offs
| Concern | Reality |
|---|---|
| Eventual consistency | Not everything works — financial ledgers need strong consistency |
| Conflict resolution | LWW loses data; CRDTs preserve but need UI for "same field edited twice" |
| Schema migrations | Harder with distributed replicas — plan for forward/backward compatibility |
| Storage | Full history (Automerge) or delta logs (CR-SQLite) grow — need GC strategy |
| Auth | Local writes need validation on sync — server still authorizes |
Bottom line
- SQLite + CRDTs + sync engine = local-first stack that works today
- Automerge 3.0 and CR-SQLite solved the memory/performance blockers
- PowerSync = best mobile support; ElectricSQL = simplest Postgres read-sync; CR-SQLite = most control
- Start small: add ElectricSQL for read-heavy views, migrate writes incrementally
- The network is now optional — design for it, don't depend on it
References
- Local-first software manifesto — Ink & Switch (2019)
- CR-SQLite GitHub — SQLite CRDT extension
- Automerge 3.0 release — 10x memory reduction
- ElectricSQL vs PowerSync vs Replicache — QueryPlane (Feb 2026)
- Comparing local-first frameworks — Neon (Sep 2024)
- Local-First Databases — QueryPlane ecosystem overview
Top comments (0)