Deploy to Railway
Deploy the production container to Railway with Railway Postgres as the durable backend for jobs, schedules and events.
Railway builds your app from its repository with the container files RelKit generates, runs it
behind HTTPS, and provides Postgres. Jobs, schedules and events live in that Postgres database
through @relkit/postgres, so a redeploy or a second instance loses nothing.
Pre-setup
Start from an app that builds, such as the api template. Install the
Railway CLI and sign in:
railway login
Railway bills by usage. The steps below create one project with one database and one service.
Deploy
Store jobs and events in Postgres
The production image keeps no durable state on its own disk: with the local filesystem provider
selected, the server refuses to start in the image (RELKIT_LOCAL_DURABLE_STATE_IN_CONTAINER).
Select the Postgres backend for jobs and events, whether or
not the app has any yet:
bun run relkit add jobs --provider postgres
bun run relkit add events --provider postgresBoth commands read the connection string from the DATABASE_URL secret. The runtime creates its
tables on first start. Check the app before anything reaches Railway:
bun run relkit checkGenerate the Railway files
bun run relkit deploy init railwayThis writes four files and changes no cloud resource:
| File | Purpose |
|---|---|
railway.json |
Build with the Dockerfile, gate each deploy on /healthz, allow a 70-second drain |
Dockerfile |
Install from bun.lock, run relkit build, run the server as a non-root user |
.dockerignore |
Keep node_modules, .relkit, .env files and Git data out of the build |
.github/workflows/railway-deploy.yml |
Check, type-check and test, then deploy every push to main with the Railway CLI |
The Dockerfile sets RELKIT_TRUST_PROXY=1: Railway terminates HTTPS in front of the service, so
the server takes the request scheme from X-Forwarded-Proto and browser requests from your
https:// domain pass its same-origin check. Add --runtime node to run the server on Node 24
instead of Bun. A file that already exists with
different content stops the command; review it, then rerun with --force to replace it. Commit the
files with bun.lock.
Create the project, database and service
railway init --name my-app
railway add --database postgres
railway add --service web --variables 'DATABASE_URL=${{Postgres.DATABASE_URL}}'If your account has more than one workspace, add --workspace <workspace ID or name> to
railway init; outside a terminal the CLI requires it.
${{Postgres.DATABASE_URL}} is a Railway reference: the service reads the database’s private URL,
which never leaves Railway’s network. Add every other required value from your defineEnv
descriptor the same way, with railway variables --service web --set NAME=value.
Deploy and open the app
railway up --ci --service web
railway domain --service webrailway up --ci uploads the directory, prints the build log and exits when the build ends.
Railway then starts the container and sends traffic to it only once /healthz answers 200,
which it does once every provider is ready. railway domain prints the HTTPS address; the first
deploy can take a few minutes to answer:
curl https://<your-domain>/healthzExpect {"status":"ready","live":true,"ready":true}.
Deploy from GitHub
The generated workflow deploys every push to main. In the Railway project, create a project token
for the environment (Project Settings → Tokens). In the GitHub repository, add it as the
RAILWAY_TOKEN secret and add a RAILWAY_SERVICE variable with the value web. Do not also
connect the repository in Railway’s service settings, or each push deploys twice.
Health checks and shutdown
| Path | Answers |
|---|---|
/healthz |
200 once providers, workers, database and auth are ready; 503 before and while draining |
/_relkit/v1/health/live |
200 while the process answers |
On a redeploy (railway redeploy --service web --yes, or a new railway up) Railway sends SIGTERM; the server stops admitting requests, finishes or cancels work in
flight and exits within its drain timeout (RELKIT_DRAIN_TIMEOUT_MS, 60 seconds by default). Leased
jobs and event deliveries that do not finish are picked up again by the next instance.
Scale out and add a worker service
Several instances of web share the database safely: each schedule occurrence runs once, and a job
or a delivery runs on one instance at a time. Raise the replica count in the service settings or with
railway scale, naming the service’s region as its settings show it:
railway scale --service web us-west2=2
To run jobs, schedules and event consumers apart from request handling, add a second service from
the same source and split the roles with RELKIT_WORKER_ROLE:
railway add --service worker --variables 'DATABASE_URL=${{Postgres.DATABASE_URL}}' --variables RELKIT_WORKER_ROLE=worker
railway variables --service web --set RELKIT_WORKER_ROLE=api
railway up --service worker
The worker uses the same railway.json and image. In GitHub, set the RAILWAY_WORKER_SERVICE
variable to worker so the workflow deploys both services.
Remove the project
Railway bills a project until it is deleted. Delete it, with its database and services, by its ID or name:
railway delete --project my-app --yes
Railway stops the project’s deployments at once and removes the project and its database 48 hours
later, so railway list still shows it until then.
Troubleshooting
- The deploy never turns healthy. Read the deploy logs with
railway logs --service web. AProvider startup failedrecord names the cause, such as a missingDATABASE_URLorRELKIT_LOCAL_DURABLE_STATE_IN_CONTAINER. bun install --frozen-lockfilefails in the build. Runbun installlocally and commit the updatedbun.lock.- POST requests are rejected. Production servers reject unsafe requests without an
Originheader that matches the app; browsers send it, and scripts must set it.