Using Railway Preview Deployments to Test Pull Requests Safely
Learn how Railway’s Preview Deployments create temporary review environments for each GitHub PR, how to configure them, and what limits to watch before you start.
07 Nov 2025, 03:04 UTC

The problem: waiting for a staging environment to test a PR
When a pull request opens, developers often need a live environment to verify changes before merging. Creating a full staging stack manually is slow, and sharing a single staging service can cause conflicts if multiple PRs are tested at once.
Thesis: Railway Preview Deployments give each PR its own isolated, disposable environment that mirrors production configuration
By linking a Railway project to a GitHub repository and enabling the Preview Deployments feature, Railway automatically spins up a temporary service for every PR. The preview uses the same Dockerfile, environment variables, and service dependencies as the production service, but runs under a unique subdomain such as preview-abc123.up.railway.app. After the PR is closed or merged, the preview is torn down, freeing resources.
How it works
- Railway watches the linked repository for pull request events.
- On PR open, it builds the service defined in
railway.yml(or the dashboard settings) and launches it as a preview. - The preview URL is posted as a comment on the PR and is also visible in the Railway dashboard.
- When the PR is closed, merged, or becomes inactive, Railway stops the preview and reclaims its compute minutes.
Worked example: enabling previews for a Node.js API
Assume you have a simple Express service with a Dockerfile and a railway.yml that defines a single service.
# railway.yml
services:
- name: web
dockerfile: Dockerfile
preview:
autoGenerateSubdomain: true # optional, default behavior
# you can override env vars for previews only
env:
NODE_ENV: preview
LOG_LEVEL: debug
Push this file to the repository’s default branch. Then, in the Railway dashboard:
- Open the project → Settings → GitHub.
- Ensure the repository is connected.
- Under “Preview Deployments”, toggle the switch to enable.
- Save.
Now open a pull request. After a few seconds, Railway will:
- Build the Docker image.
- Start the service with the preview‑specific environment variables.
- Post a comment like
Preview deployed: https://preview-abc123.up.railway.app.
You can click that URL to run manual QA or point automated test suites at it.
Verification steps you can perform
- Check the Railway logs for the preview build: in the dashboard, select the preview service → “Logs”. Look for lines that show the Docker build and the environment variables you set (
NODE_ENV=preview). - Visit the preview URL and confirm the app responds as expected.
- Open the project’s “Usage” page. You should see preview minutes deducted from your monthly quota proportional to the preview’s runtime.
Trade‑offs and limitations
- Resource sharing: Previews run on the same underlying infrastructure as other services in your project. Running heavy load tests (e.g., sustained high‑request traffic) can consume compute minutes that affect other previews or even production if you exceed your project’s limits.
- Free‑tier limits: The free tier includes a limited number of preview minutes per month. If you frequently open many long‑lived PRs, you may exhaust those minutes and need to upgrade or manually disable previews for low‑risk branches.
- Monorepo considerations: Railway triggers a preview for any PR that changes files in the linked repository. In a monorepo where only a subset of directories relates to a service, you can add a
pathfilter in the GitHub integration settings to limit preview builds to relevant folders. - State isolation: Each preview gets a fresh filesystem and network, but any external services (databases, caches) that are shared via environment variables will be the same as production unless you override them in the
previewblock ofrailway.yml. Be careful not to accidentally point a preview at a production database.
Actionable closing
If you want faster, safer feedback on pull requests, start by adding a minimal railway.yml with a preview block, enable the feature in the dashboard, and monitor the usage page for the first few PRs. Adjust environment variables or resource limits as needed, and consider path filters for monorepos to avoid unnecessary builds. Once the preview URLs appear in your PR comments, you have a disposable, production‑like environment ready for both manual QA and automated tests—without the overhead of managing a separate staging cluster.