Using Railway Preview Deployments to Test Pull Requests in Real Time
Learn how Railway Preview Deployments give each Git branch its own isolated, shareable environment, letting you test pull requests instantly without manual staging setup.
05 Jul 2026, 03:51 UTC

The problem: waiting for a staging environment slows down code review
When a team relies on a single shared staging server, every pull request (PR) must wait for a slot, and manual steps are needed to spin up a test database or cache. This creates bottlenecks, especially when multiple branches are active simultaneously.
Thesis: Railway Preview Deployments give each branch its own isolated, shareable environment automatically, letting reviewers test changes instantly without manual setup.
How Preview Deployments work
When you connect a GitHub, GitLab, or Bitbucket repository to a Railway project and enable Preview Deployments, Railway watches for pushes. On each push to a branch:
- Railway clones the repository.
- It builds the Dockerfile or uses the detected buildpack, reusing the same cache as production.
- It provisions a temporary app that inherits the project’s defined services (databases, caches, etc.), cloning them with ephemeral data.
- The preview receives a unique subdomain of the form
<project>-<branch>.up.railway.app. - Environment variables follow the project’s inheritance rules but can be overridden per‑branch via the Railway UI or a
railway.ymlfile.
The preview lives as long as the branch exists; closing the PR or deleting the branch triggers automatic teardown.
Worked example: setting up and verifying a preview
Assume you have a sample Node.js app with a Dockerfile and a PostgreSQL service already defined in the Railway project.
Prerequisites
- A Railway account (paid plan or free tier with preview quota).
- Git installed locally and access to the repository.
- The Railway CLI (
railway) installed and you are logged in (railway login).
Steps
- Link the repository (run in your local terminal):
Permissions: You need push access to the repository and the ability to create resources in the Railway project. Risk: Linking does not change any existing resources; it only configures the CLI.# Clone the repo if you haven’t already git clone https://github.com/your-org/sample-node-app.git cd sample-node-app # Link the local repo to the Railway project railway link # selects your project interactively - Enable Preview Deployments via the Railway dashboard: Project → Settings → Previews → toggle “Enable Preview Deployments”.
- Create a feature branch and push it:
Where to run: Local development machine. Expected check: Within a minute, the Railway dashboard shows a new preview under the “Previews” tab with a URL likegit checkout -b feature/new-login # make a trivial change, e.g., update README echo "# Test preview" >> README.md git add README.md git commit -m "Add preview test note" git push -u origin feature/new-loginsample-node-app-feature-new-login.up.railway.app. - Verify the preview runs: Open the URL in a browser; you should see the updated README reflected in the app (if your app serves it) or at least a successful HTTP 200 response.
- Test an override: Add a
railway.ymlto the branch to change an environment variable, e.g., set a feature flag.
Commit and push the file:# railway.yml preview: env: FEATURE_NEW_LOGIN: "true"
After the rebuild, revisit the preview URL and confirm the variable is applied (e.g., by checking an endpoint that returnsgit add railway.yml git commit -m "Add preview env override" git pushprocess.env.FEATURE_NEW_LOGIN). The production environment remains unchanged because overrides are scoped to the preview. - Tear down the preview: Delete the branch or close the PR.
Expected check: The preview disappears from the Railway dashboard within a few seconds, and the associated quota usage drops.git push origin --delete feature/new-login
Trade‑offs and limitations
- Resource consumption: Each preview uses the same monthly compute and memory quota as a regular service. On the free tier, running many long‑lived previews can exhaust the quota quickly, leading to throttling.
- Ephemeral data: Cloned services (databases, caches) start empty or with a fresh copy of the defined data; any state changes made during testing are lost when the preview is torn down. This limits tests that rely on persistent state across preview runs.
- Concurrency limits: Free accounts allow only a limited number of concurrent previews. Teams with many active branches may need to upgrade to a paid plan or manually prune old previews.
Actionable closing
If your team struggles with staging bottlenecks, enable Railway Preview Deployments for a representative repository and try the workflow above. Monitor quota usage in the Railway dashboard to gauge whether your current plan supports the preview load. Adjust the preview lifetime (e.g., by setting a branch‑expiration policy in your Git host) to keep costs predictable while still giving reviewers instant, production‑like environments for every pull request.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.