Railway
01 / 02

Railway: Environments, Config & Production Practices

Railway: Environments, Config & Production Practices

Environments & PR Previews

Environments let a project run isolated copies of its services -- separate variables, databases, deployments -- for different purposes: a production environment for live traffic, plus staging or automatic PR-based preview environments for reviewing changes before they reach users.

railway.json: Version-Controlled Deploy Config

{
  "build": {
    "builder": "NIXPACKS"
  },
  "deploy": {
    "startCommand": "npm run start:prod",
    "healthcheckPath": "/health",
    "restartPolicyType": "ON_FAILURE",
    "restartPolicyMaxRetries": 3
  }
}

Committing deploy configuration to the repo (rather than only setting it through the dashboard) keeps it version-controlled and applied consistently across environments.

Health Checks

// Railway periodically requests the configured path to confirm the
// deployment is actually responding correctly before routing traffic
// to it -- avoids sending users to a still-starting or broken instance
app.get('/health', (req, res) => {
  res.status(200).send('ok')
})

Monorepo Deployments

A single repository containing multiple apps (e.g. /frontend and /backend) can have each subdirectory configured as its own Railway service with an independent build/deploy pipeline via its 'root directory' setting -- no need to split into separate repos.

Custom Domains & Rollbacks

  • A public *.up.railway.app domain is auto-provisioned for a web service; a custom domain can be attached via DNS records configured in the dashboard.

  • Rollback quickly reverts a service to a previous, known-good deployment if a new deploy breaks production -- much faster than reverting Git history and waiting for a fresh build during an incident.

  • Cron-scheduled services run on a fixed schedule rather than continuously -- useful for periodic tasks like a nightly cleanup job, without hosting separate scheduling infrastructure.

  • Templates provide pre-configured, one-click-deployable project blueprints already wired up for a common stack (e.g. Postgres + Redis + app).

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free