Skip to content
PricingBlog
✨ Markdown

Postgres Sync

Read-path sync engine for Postgres that handles partial replication, data delivery and fan-out.

Postgres sync engine

Postgres Sync is a sync engine that syncs subsets of your data out of your Postgres database, into local apps and services.

You can sync data into anything you like. From web, mobile and desktop apps and client stores like TanStack DB to databases like PGlite.

🎓  A quick note on naming

Postgres Sync used to just be called "Electric" or the "Electric sync engine". Some docs and package names still use the old naming.

How does it work?

Postgres Sync connects to your Postgres using a DATABASE_URL, consumes the logical replication stream and fans out data into Shapes, which Clients then consume and sync.

Shape log flow diagram
Shape log flow diagram.

Technically, Postgres Sync is an Elixir application, developed at packages/sync-service. It runs as a seperate service, between your API and your database. Clients consume data over an HTTP API that works with CDNs to scale data delivery and fan-out.

Illustration of the main components of a successfull deployment

The same shape log is delivered to every subscriber — web tabs, mobile devices, server workers, agents — in real time, with the same ordering and guarantees. This allows you to have millions of concurrent users subscribing to real-time updates to your database with minimal additional load on your database.

Define a Shape — sync just what you need

A Shape is a SQL query against your Postgres. Postgres Sync carves out the matching rows and keeps them live for every client that subscribes.

Shape:
define a shape
SELECT *
FROM issues
WHERE assignee = 'alex'
  AND status = 'open'
rows matched3
scope3 / 8
postgres · issues
  • #101alexP0openWire new auth flow
  • #102jenP2doneUpdate changelog
  • #103alexP1openFix race in worker
  • #104kaiP0blockedPostgres upgrade
  • #105samP1doneRefactor router
  • #106alexP2openDoc the API
  • #107jenP0openCustomer demo prep
  • #108kaiP0doneShip release notes
streams to client
client · live shape3 rows
  • #101alexP0Wire new auth flow
  • #103alexP1Fix race in worker
  • #106alexP2Doc the API

See the Shapes guide for the full shape definition syntax, including where clauses, columns projection, and progressive loading.

Query-driven sync

Your shape defines the outer bounds — the slice of Postgres a user is allowed to see. Live queries running on the client narrow that slice further, syncing only the rows actually needed for the current view.

SHAPE workspace.issues where org_id = $user.org_id98 rows
WHERE priority = 'urgent' loads 15 / 98 rows

TanStack DB has this built in. Pick the sync mode that fits the work: eager to preload everything for instant interactions, on-demand to fetch only what the current query needs, or progressive to start fast and fill in the rest in the background.

See the Live queries guide for the full TanStack DB sync-mode reference.

Bring your own writes

Postgres Sync handles the read path. Writes go through your existing backend — pick how much sync you want on top.

01
Plain API

Write through your API

POST or PUT to your existing endpoints. The Postgres txid flows back through the read path.

Learn more →
02
API + clients

Shared write path

Many clients hit the same backend. Sync delivers the same change to every reader.

Learn more →
03
+ TanStack DB

Optimistic mutations

UI updates instantly. The collection awaits the txid on the stream and reconciles.

Learn more →

See the Writes guide for the four write patterns and how to pair them with optimistic mutations in TanStack DB.

More information

See the Quickstart, the Stacks overview, and the HTTP API reference. The full source is on GitHub at electric-sql/electric.