
Deploy ElectricSQL | Postgres Sync Engine, Database Included
Electric sync engine + Postgres with logical replication already on.
postgres
Just deployed
/var/lib/postgresql
electric
Just deployed
/var/lib/electric/persistent
Deploy and Host ElectricSQL with Postgres on Railway
ElectricSQL is an open-source Postgres sync engine. It streams little subsets of your Postgres data — called shapes — out to local apps over a simple HTTP API, so your frontend reads from a local cache that stays live instead of round-tripping to your API on every render. This template ships Electric together with its own Postgres, already configured for logical replication, so there is nothing to fill in and nothing to reconfigure.
About Hosting ElectricSQL with Postgres
Electric's one hard requirement is a Postgres running with wal_level = logical and a role holding the REPLICATION attribute. That is exactly the setting most managed Postgres providers leave off by default, and it is the step that turns "just point Electric at your database" into an afternoon of provider documentation.
This template removes that step. It deploys two services: the official postgres:18.4-trixie image started with -c wal_level=logical -c max_wal_senders=10 -c max_replication_slots=10, and the official electricsql/electric image already pointed at it over Railway's private network. Postgres data persists on a volume at /var/lib/postgresql; Electric's shape logs persist on their own volume at /var/lib/electric/persistent, so a redeploy does not force every client to re-sync from scratch. Electric follows Railway's injected $PORT, listens on IPv6 for the private network, and exposes /v1/health for the platform healthcheck.
The deploy form is empty. POSTGRES_PASSWORD and ELECTRIC_SECRET are generated for you at deploy time, and DATABASE_URL is wired from the Postgres service by reference — you click deploy and get a working sync engine with a database behind it.
Why Deploy ElectricSQL with Postgres on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying ElectricSQL on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, sync engines, and more on Railway.
- Nothing to configure — logical replication, the replication role, private networking, and both volumes are already wired.
- Database included — no separate Postgres to provision, and no provider whose logical replication settings you cannot change.
- Real-time reads without websockets — Electric's HTTP API is cacheable by any CDN or proxy; there is no bespoke socket server to run.
- Secure by default —
ELECTRIC_SECRETis generated at deploy and required on every shape request; only/v1/healthstays open.
Common Use Cases
- Local-first and offline-capable apps — keep a live local copy of the rows a user actually needs, and read from it instantly.
- Real-time dashboards and collaborative UIs — stream inserts, updates, and deletes straight out of Postgres without polling.
- Replacing hand-rolled websocket layers — drop the bespoke pub/sub service and let Postgres' own replication stream be the source of truth.
Dependencies for ElectricSQL Hosting
- A Postgres running with logical replication enabled — included in this template, no external database required.
- A volume for Postgres data at
/var/lib/postgresql(included). - A volume for Electric's shape logs at
/var/lib/electric/persistent(included).
Deployment Dependencies
- ElectricSQL — upstream sync engine by Electric DB Ltd (Apache-2.0)
- ElectricSQL documentation — HTTP API and client reference
- electricsql/electric Docker image — the official image this template deploys
- postgres Docker image — the official Postgres image this template deploys
Implementation Details
Create a table in the bundled Postgres, then read it back through Electric as a shape:
# 1. create a table (via any Postgres client connected to the postgres service)
CREATE TABLE items (id int PRIMARY KEY, name text);
INSERT INTO items VALUES (1, 'alpha'), (2, 'beta');
# 2. read the initial snapshot through Electric
curl 'https:///v1/shape?table=items&offset=-1&secret=$ELECTRIC_SECRET'
# 3. follow live changes from the offset and handle the response returned above
curl 'https:///v1/shape?table=items&handle=$HANDLE&offset=$OFFSET&live&secret=$ELECTRIC_SECRET'
Inserts, updates, and deletes arrive on the live endpoint as they are committed. Official client libraries are available for TypeScript, React, and React Native, plus integrations for TanStack Query and Phoenix.
Template Content
postgres
postgres:18.4-trixieelectric
electricsql/electric:1.7.8