ElectricSQL syncs data between your Postgres database and local SQLite on every client device. Your app works offline, syncs when connected, and handles conflicts automatically. It's local-first made easy.
What Makes ElectricSQL Special?
- Postgres to SQLite sync — automatic, bidirectional
- Offline-first — full app functionality without internet
- Conflict resolution — automatic CRDT-based merging
- Shape subscriptions — sync only the data you need
- Free — open source, self-hosted
The Hidden API: Shape Subscriptions
import { ShapeStream, Shape } from '@electric-sql/client';
// Subscribe to a subset of your Postgres data
const stream = new ShapeStream({
url: 'http://localhost:3000/v1/shape',
params: {
table: 'items',
where: 'status = \'active\'',
columns: ['id', 'title', 'completed', 'created_at']
}
});
const shape = new Shape(stream);
// Get current data (works offline!)
const items = [...shape.valueSync.values()];
// Subscribe to changes
shape.subscribe(({ rows }) => {
console.log('Data changed:', rows.size, 'items');
updateUI(rows);
});
React Integration
import { useShape } from '@electric-sql/react';
function TodoList({ projectId }: { projectId: string }) {
const { data: todos } = useShape({
url: 'http://localhost:3000/v1/shape',
params: {
table: 'todos',
where: `project_id = '${projectId}'`
}
});
// This auto-updates when data changes in Postgres!
// And works offline!
return (
<ul>
{todos.map(todo => (
<li key={todo.id}>{todo.title}</li>
))}
</ul>
);
}
Write Path — Standard Postgres
// Writes go through your existing API to Postgres
// ElectricSQL syncs changes to all clients automatically
await fetch('/api/todos', {
method: 'POST',
body: JSON.stringify({ title: 'New task', projectId: '123' })
});
// All connected clients see the new todo instantly!
Quick Start
npm install @electric-sql/client @electric-sql/react
# Run Electric sync service alongside Postgres
docker compose up electric postgres
Why Teams Choose ElectricSQL
A mobile developer shared: "Our field workers use the app in areas with no cell coverage. ElectricSQL lets them work all day offline, and everything syncs when they're back in range. Zero data loss, zero conflicts, zero custom sync code."
Building offline-first apps? Email spinov001@gmail.com or check my tools.
Local-first or cloud-first? How do you handle offline?
Top comments (0)