
Deploy ElectricSQL + Postgres 18 | (Just Updated) Real-Time Sync Engine, Database Included, Write From Anywhere
Electric sync engine + Postgres 18, logical replication on, public psql URL
electric
Just deployed
/var/lib/electric/persistent
postgres
Just deployed
/var/lib/postgresql
Deploy and Host ElectricSQL + Postgres 18 on Railway
ElectricSQL is an open-source Postgres sync engine. It streams subsets of your Postgres data, called shapes, to local apps over a plain HTTP API, so your frontend reads from a live local copy instead of calling your API on every render. This template deploys Electric together with its own Postgres 18, with logical replication already on and a public, TLS-encrypted connection string, so you can write to the database from your laptop the moment the deploy goes green.
Write a row, read it through Electric. Your first two minutes:
# 1. Write. Copy DATABASE_PUBLIC_URL from the postgres service's Variables tab.
psql "$DATABASE_PUBLIC_URL" -c "CREATE TABLE items (id int PRIMARY KEY, name text);
INSERT INTO items VALUES (1, 'alpha');"
# 2. Read. Copy ELECTRIC_SECRET from the electric service, and use its public domain.
curl "https:///v1/shape?table=items&offset=-1&secret=$ELECTRIC_SECRET"
The same DATABASE_PUBLIC_URL works in any migration tool (Prisma, Drizzle, Rails, Django, Alembic) and any GUI client. An app deployed in the same Railway project should use the private DATABASE_URL instead.
Already running your own Postgres with logical replication? Use ElectricSQL with your own Postgres instead and point it at your database.
About Hosting ElectricSQL + Postgres 18
Electric has one hard requirement: a Postgres running with wal_level = logical, and a role that holds the REPLICATION attribute. Most managed Postgres providers leave that setting off and many do not let you change it, which turns "point Electric at your database" into an afternoon of provider documentation. This template removes that step.
It deploys two services:
- postgres: the official
postgres:18.6image, pinned by digest, started withwal_level=logical,max_wal_senders=10andmax_replication_slots=10. Data lives on a volume at/var/lib/postgresql. Postgres 18 moved its data directory to/var/lib/postgresql/18/docker, so the volume is mounted one level up, where the image expects it. Railway's TCP proxy exposes the database publicly, and TLS is switched on with a certificate generated on first boot and kept on the volume, so your password never crosses the internet in plain text. - electric: the official
electricsql/electric:latestimage, connected to Postgres over Railway's private network. Its shape logs persist on a second volume at/var/lib/electric/persistent, so a redeploy does not force every client to re-sync./v1/healthdrives the Railway healthcheck.
Both services restart on failure. Measured idle on Railway: about 50–100 MB for Postgres and 300–330 MB for Electric. Both services also ran healthy and served shapes under a 512 MB memory limit each, so the stack fits Railway's Free and Trial plans.
Why Deploy ElectricSQL + Postgres 18 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 + Postgres 18 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 fill in.
POSTGRES_PASSWORDandELECTRIC_SECRETare generated for each deploy, and every connection string is wired by reference. - You can write to it. A public
DATABASE_PUBLIC_URL(TLS,sslmode=require) is ready on day one, so you can run migrations and seed data without first deploying something else into the project. - Postgres 18, logical replication on. The setting Electric needs is already in place.
- Data survives redeploys. Both services keep their state on volumes.
- Locked by default. Every
/v1/shaperequest needsELECTRIC_SECRET; only/v1/healthis open.
Common Use Cases
- Local-first and offline-capable apps: keep a live local copy of the rows a user needs and read it instantly.
- Real-time dashboards and collaborative UIs: stream inserts, updates and deletes out of Postgres without polling.
- Replacing a hand-rolled websocket layer: let Postgres' own replication stream be the source of truth, served over cacheable HTTP.
Dependencies for ElectricSQL + Postgres 18 Hosting
- A Postgres with logical replication enabled: included (Postgres 18.6).
- 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, the upstream sync engine (Apache-2.0)
- ElectricSQL HTTP API docs
- electricsql/electric Docker image
- postgres Docker image
Implementation Details
Follow live changes after the initial snapshot. Take electric-handle and electric-offset from the response headers of the previous request:
curl "https:///v1/shape?table=items&handle=$HANDLE&offset=$OFFSET&live=true&secret=$ELECTRIC_SECRET"
Inserts, updates and deletes arrive on the live endpoint as they are committed. Keep ELECTRIC_SECRET on your server: put a small proxy in front of Electric that adds the secret and checks your own auth, as the Electric security guide describes, rather than shipping the secret to browsers. Official clients exist for TypeScript, React and React Native, with integrations for TanStack DB and Phoenix.
Template Content
electric
electricsql/electric:latestpostgres
postgres:18.6