Skip to content

Sync with your stack

Electric provides composable sync primitives.

This allows you to add real-time sync to your existing stack, without imposing technology choices, code changes or data silos.

Sync stacks

We've picked four different sync stacks to illustrate four different ways of integrating Electric into your stack of choice.

Core architecture

All of these sync stacks are based on the same core architecture.

Electric always runs as a service in front of Postgres, syncing into a Client process or store, via a Proxy or backend API.

Illustration of the main components of a successfull deployment

You can learn more about these by following Deployment guide.

Choosing a stack

We recommend using TanStack DB for web and mobile app development. It's super fast, lightweight, type-safe and gives you an optimal, end-to-end, local-first sync stack.

You can also combine TanStack DB with Phoenix.Sync if you're building agentic systems with Elixir or looking for a batteries-included backend framework.

PGlite and Yjs are more for specialist use-cases where you're syncing into a dev, test or CI environment or crafting a multi-user collaboration system, respectively.

Choosing a Postgres host

Electric works with any Postgres with logical replication enabled. Neon, Supabase and Crunchy are all great choices for a Postgres host.

Hosting your proxy

You can proxy requests to Electric either through your backend API, or through a cloud worker. Cloudflare is a great choice for hosting workers because it only charges for actual processing time (not for wall clock time holding sync connections open).

Other stacks

The stacks on this page are just some options and recommendations. You can use Electric with any technology you like — as long as it speaks HTTP and JSON.

For example, sync into LiveStore for a principled, event-sourcing based development model. Or distributed SQlite or native iOS apps.

TanStack

Great for super fast web, mobile and AI app development.
DatabaseBackendSchemaProxyClientWrites
PostgresTanStack StartDrizzleCloudflareTanStack DBtRPC

Tanstack DB is a reactive client store for building super fast apps on sync.

Paired with Electric and TanStack Start, it gives you an end-to-end sync stack that's type-safe, declarative, incrementally adoptable and insanely fast.

End-to-end Typescript

See the tanstack-db-web-starter for an example of an end-to-end Typescript stack for web app development:

See also the tanstack-db-expo-starter for a similar stack for mobile app development.

Incremental adoption

TanStack DB is designed to be incrementally adoptable into existing applications.

It's tiny — a few Kbs — so doesn't introduce a big dependency. It works with all major front-end reactivity frameworks. It works with API-based data loading and sync. So you can progressively adopt by first migrating API-based apps using TanStack Query and then migrate to sync without affecting the component code.

Super fast 🔥

When you combine Electric with TanStack DB, you get blazing fast end-to-end reactivity.

Components use live queries to react and when data changes. These are based on a Typescript implementation of differential dataflow. This means you can build complex client apps where everything reacts instantly, within a single animation frame.

More information

Phoenix

Great for agentic systems and full-stack development.
DatabaseBackendSchemaProxyClientWrites
PostgresPhoenixEctoPhoenixTanStack DBPhoenix

Phoenix is a full-stack web development framework for Elixir.

Electric is developed in Elixir, has a first-class Elixir client and a deep Phoenix framework integration in the form of the official Phoenix.Sync library.

Phoenix.Sync

Phoenix.Sync enables real-time sync for Postgres-backed Phoenix applications. You can use it to sync data into Elixir, LiveView and frontend web and mobile applications.

Using with TanStack DB

Read-path sync works naturally with TanStack DB. Plus it provides:

Building agentic systems

Phoenix is built in Elixir, which runs on the BEAM. The BEAM provides a robust agentic runtime environment with built-in primitives for process supervision and messaging.

This makes Elixir and Phoenix a perfect match for agentic system development without needing a seperate agent framework.

More information

PGlite

Great for dev, test and sandbox environments.
DatabaseClientWrites
PostgresPGliteCustom

PGlite is an embeddable Postgres database.

Electric can sync data into PGlite to hydrate lightweight database instances for dev, test and sandboxed environments

Lightweight developer database

Platforms including Google Firebase, Supabase and Prisma all use PGlite as a development database. It's proper Postgres that can run embedded, in-process. So you don't need any external processes or system packages to use it.

Having a Postgres database is as simple as:

shell
npm install @electric-sql/pglite
ts
import { PGlite } from '@electric-sql/pglite'

const db = new PGlite()

Database in the sandbox

AI app builders like Bolt, Lovable and Replit can generate database-driven apps and run them in a sandboxed dev environment. However, to actually work, these apps need to connect to a database.

PGlite is a Postgres database that runs inside your dev environment. With it, you can one-shot database-driven apps that run without leaving the sandbox.

Hydrating PGlite

Electric can be used to hydrate data into a PGlite instance using the sync plugin:

ts
import { electricSync } from '@electric-sql/pglite-sync'

const pg = await PGlite.create({
  extensions: {
    electric: electricSync(),
  },
})

This supports individual tables and transactionally syncing multiple tables.

More information

Yjs

Great for fine-tuned realtime collaboration.
DatabaseClientWrites
PostgresYjsYjs

Yjs is a library for building collaborative applications.

Conflict-free updates

Electric can be used as a transport layer with Yjs to create collaborative, multi-user applications on top of Postgres.

Multi-user collaboration

This works by exposing a Shape to sync changes for a Y.Doc. The y-electric package then automatically shares updates across all connected clients.

More information