Home / Insights / Architecture and Modernization

Architecture and Modernization

Preview Environments per Pull Request: Faster Review and QA Without Runaway Costs

A shared staging server forces every change to queue behind every other change. Preview environments give each pull request its own running copy of the product, so reviewers, testers and product owners can check work before it merges. Here is how to set them up without creating a security or cost problem.

TopicsArchitecture and ModernizationQA and Software Testing

Key takeaways

  • Preview environments move feedback before the merge, which removes the shared-staging queue and makes QA and product review part of each pull request.
  • Choose the scope deliberately: frontend-only previews are cheap and quick; full-stack previews catch more but need seeded data, isolated databases and stubbed integrations.
  • Automatic teardown is not optional. Stop environments on merge or close, and after a period of inactivity, or costs and stale URLs will pile up.
  • Never give untrusted pull request code access to deployment secrets. Keep preview credentials separate from staging and production, with least privilege.
  • Start with one service and one team, measure review turnaround and escaped defects, then expand.

Most teams we work with have the same bottleneck at some point: one staging environment, many developers. A tester cannot verify a fix because someone else has just deployed a half-finished feature over it. A product owner waits until Thursday to see a change that was ready on Monday. Bugs that a five-minute look would have caught make it into the main branch because nobody could easily run the branch.

Preview environments, also called review apps or ephemeral environments, solve this by deploying every pull request to its own temporary URL. This article is for CTOs, engineering managers and QA leads deciding whether to adopt them. It explains what they change, the architecture options and their trade-offs, how to handle data, secrets and security, what they cost, and how to roll them out in stages. It ends with a checklist.

What do preview environments change in your workflow?

A preview environment is a short-lived deployment of the application built from a single branch or pull request. It is created when the pull request opens or updates, linked from the pull request page, and destroyed when the pull request is merged or closed.

GitLab, which calls them review apps, describes them as temporary test environments created automatically for each branch or merge request, with a “View app” link in the merge request once the pipeline finishes (GitLab Docs: Review apps). GitHub Actions supports the same pattern: a job that targets an environment can set a deployment URL, which then appears as a “View deployment” button in the pull request timeline (GitHub Docs: Using environments for deployment).

Who benefits

  • Code reviewers can click through the change instead of reading a diff and imagining it.
  • QA engineers test each change in isolation, so a failure clearly belongs to one pull request.
  • Product owners and designers approve behaviour and visuals before merge, when changes are cheap.
  • Automated tests such as end-to-end and visual regression suites run against a realistic deployment rather than a local build.

What they do not replace

Preview environments do not replace a stable staging or pre-production environment that mirrors production for integration, performance and release testing. They complement it: previews for per-change feedback, staging for release confidence. Our article on designing a CI/CD pipeline covers where each stage fits.

Action: measure how long changes currently wait for review or QA after the code is ready. That number is the baseline your preview environments should reduce.

Which preview architecture fits your product?

The main decision is how much of the system each preview contains. More fidelity catches more problems, but costs more and takes longer to start.

ApproachWhat is deployed per PRStrengthsTrade-offs
Frontend-only previewStatic or server-rendered frontend pointing at a shared backendCheap, fast, simple; ideal for UI and content changesCannot test backend changes; shared backend data can be polluted
Full stack per PR (containers)Frontend, API, workers and a database per PR, often in its own Kubernetes namespaceHighest isolation; tests backend and migrationsHighest cost and start-up time; needs seed data and stubs
Hybrid: changed services onlyOnly services changed in the PR, routed alongside shared baseline servicesScales to many microservices; lower costRequires request routing and careful versioning between services
Platform-managed previewsHosting platform builds and hosts previews automaticallyMinimal setup for supported stacksLess control; may not cover workers, queues or private networking

How to choose

  • Mostly UI work, stable API: start with frontend-only previews.
  • Monolith or a few services with frequent schema changes: full stack per pull request, with a small database.
  • Many microservices: hybrid routing, so a PR touching one service does not spin up twenty.
  • Mobile apps: the equivalent is a per-PR build distributed to testers through internal testing tracks, pointed at a preview backend.

For example, a 15-developer SaaS team with a Next.js frontend, one Node.js API and PostgreSQL might deploy each pull request as three containers in its own Kubernetes namespace with a small database seeded from fixtures, and stub its payment and email providers. That gives QA a complete, isolated system for each change.

Action: map your services and mark which ones change most often. Preview what changes; share what does not.

How should previews handle data and third-party integrations?

An empty database makes a preview nearly useless, and a copy of production data makes it a liability. Data design is usually the hardest part.

Data options

  1. Seed from fixtures: a script creates realistic accounts, records and edge cases on start-up. Fast, safe and repeatable. This should be the default.
  2. Snapshot of an anonymised dataset: a periodically refreshed, de-identified dataset restored per preview. More realistic, but the anonymisation must be reviewed and maintained.
  3. Database branching: some managed database services can create copy-on-write branches quickly. Useful for large schemas; check cost and data residency.
  4. Never production data: personal data in short-lived environments with broad developer access creates privacy and breach risk. Avoid it.

Migrations

Run schema migrations on every preview start. This is one of the most valuable checks previews provide, because a broken migration is found before it reaches staging.

Third-party services

  • Payments: use the provider’s test mode with test keys only.
  • Email and SMS: route to a capture service or sandbox so no real customer is contacted.
  • Webhooks and OAuth callbacks: dynamic URLs often break redirect allow-lists; use a stable gateway that routes by subdomain, or stub the integration.
  • AI model APIs: set strict quotas or a cheaper model for previews, and cache responses for test runs.

Action: list every external integration and decide for each one: real sandbox, local stub or disabled in previews.

How do you keep preview environments secure?

Preview environments run code that has not been reviewed yet. That changes the threat model.

Untrusted code and secrets

The risk is greatest in repositories that accept contributions from forks, including open source projects and repositories shared with contractors. GitHub Security Lab warns that workflows triggered by pull_request_target run with write access and the repository’s secrets, and that combining this trigger with a checkout and build of the untrusted pull request is dangerous, because install scripts and build steps can execute attacker code. It recommends doing unprivileged work under pull_request, passing results as artifacts to a separate privileged workflow, and treating those artifacts as data only (GitHub Security Lab: Preventing pwn requests). It also notes that label-based approval is only a stopgap, because new commits can be pushed after approval.

Practical controls

  • Separate credentials: previews get their own cloud account or project, with deploy credentials that cannot touch staging or production.
  • Environment protection: use your CI platform’s environment rules to restrict which branches and workflows can deploy and which secrets each job sees.
  • Access control on URLs: put previews behind single sign-on or an identity-aware proxy. Unreleased features and test data should not be public or indexed.
  • Network isolation: previews should not reach production databases or internal admin systems.
  • Short lifetime: the shorter an environment lives, the smaller the window for misuse.

Our DevSecOps checklist covers pipeline security more broadly.

Action: ask “what could a malicious pull request do in our preview pipeline?” and fix every answer that involves secrets or production access.

What do preview environments cost, and how do you control it?

Costs scale with the number of open pull requests multiplied by the resources each preview uses and how long it lives. Forgotten environments are the most common source of waste.

Teardown rules

GitLab’s documentation shows both mechanisms you need: an on_stop job that runs when the merge request is merged or the branch is deleted, and an auto_stop_in setting, for example one week, that stops an environment after a period of inactivity (GitLab Docs: Review apps). Implement both on any platform: event-based teardown for the normal path, time-based teardown for everything that slips through.

Resource limits

If previews run on Kubernetes, give each one its own namespace and a quota. The Kubernetes documentation describes a ResourceQuota as a per-namespace constraint on aggregate resource consumption and object counts, designed to stop one team or workload using more than its fair share of a shared cluster (Kubernetes: Resource quotas). Add default requests and limits so a misconfigured preview cannot starve others.

Other levers

LeverEffectWatch out for
Scale to zero when idleLarge saving outside working hoursCold-start delay for the first visitor
Spot or pre-emptible nodesCheaper compute for disposable workloadsInterruptions; fine for previews, not for staging
Small shared database server with one database per PRFewer instances to pay forNoisy neighbours; enforce connection limits
Opt-in previews (label or command)Only PRs that need review get an environmentTeams may forget; make it the default for UI changes
Build cachingFaster start, less CI timeCache invalidation errors

Our guide to Kubernetes cost control covers right-sizing, autoscaling and spot capacity in more depth.

Action: tag every preview resource with its pull request number and report weekly on active previews and spend. Visible costs stay under control.

How do you roll out preview environments step by step?

  1. Pick a pilot: one repository and one team with frequent UI or API changes and an active QA function.
  2. Containerise and template: the application must build and start from a single definition (for example, a Helm chart or Terraform module) with the environment name as a parameter.
  3. Automate create and update: on pull request open or push, build images, deploy to a namespace or project named after the PR, run migrations and seed data, then post the URL to the pull request.
  4. Automate teardown: on merge or close, destroy everything; add an inactivity timeout and a nightly sweep for orphans.
  5. Wire in tests: run smoke, end-to-end and accessibility checks against the preview URL and report results on the pull request.
  6. Change the review process: make “checked in preview” part of the definition of done for user-facing changes, with QA and product sign-off on the pull request.
  7. Measure and expand: after a few weeks, compare review turnaround, rework and escaped defects with the baseline, then roll out to more repositories.

Making QA part of the pull request

The process change matters as much as the tooling. QA engineers should test in the preview, record results on the pull request and block the merge when needed, rather than testing batches on staging after the fact. That shift is the core of continuous testing.

At PoliteTech, our Cloud and DevOps team builds CI/CD pipelines with GitHub Actions, GitLab CI, Azure DevOps or Jenkins, infrastructure as code with Terraform, Docker and Kubernetes on AWS, Azure and Google Cloud, plus the monitoring and secrets management that preview environments depend on.

Checklist before you switch on preview environments

  1. Scope chosen: frontend-only, full stack, or changed services only.
  2. Application deploys from one parameterised template.
  3. Seed data script covers key roles, records and edge cases; no production personal data.
  4. Migrations run on every preview start.
  5. Payments, email, SMS and AI APIs use sandboxes, stubs or strict quotas.
  6. Preview credentials are isolated from staging and production.
  7. Fork and contractor pull requests cannot reach secrets.
  8. Preview URLs require sign-in and are not indexed.
  9. Teardown on merge or close, plus inactivity timeout and orphan sweep.
  10. Namespace quotas and default limits in place; resources tagged by PR.
  11. Automated tests run against the preview URL and report on the PR.
  12. Review process updated so QA and product sign off in the preview.

Frequently asked questions

Do preview environments replace our staging environment?

No. Previews give fast, isolated feedback on individual changes. A stable staging or pre-production environment is still needed for release testing, integration with real partner sandboxes and performance checks.

How much do preview environments cost?

It depends on how many pull requests are open, how much each preview runs and how long it lives. Frontend-only previews are inexpensive; full-stack previews cost more. Automatic teardown, scale-to-zero and namespace quotas keep costs predictable.

Can we use preview environments with microservices?

Yes, but deploying every service per pull request rarely makes sense. Deploy only the changed services and route requests for the rest to a shared baseline, using headers or subdomains to select the preview version.

Are preview environments safe for open source or contractor contributions?

They can be, if untrusted pull request code never runs with deployment secrets or write tokens. Build untrusted code in an unprivileged workflow, deploy with isolated credentials and keep previews away from production networks.

What about mobile apps?

The equivalent is an automatic per-pull-request build distributed through internal testing channels, connected to a preview backend. Testers install the build linked from the pull request and test that change in isolation.

Sources and methodology

Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.

  1. GitLab Docs: Review apps — accessed 9 November 2026. Per-branch dynamic environments, View app links, on_stop teardown on merge and auto_stop_in inactivity timeouts.
  2. GitHub Docs: Using environments for deployment — accessed 9 November 2026. Environment rules applying to jobs and deployment URLs shown as a View deployment button on pull requests.
  3. GitHub Security Lab: Keeping your GitHub Actions and workflows secure – preventing pwn requests — accessed 9 November 2026. Risks of pull_request_target with untrusted code, safe split-workflow pattern and limits of label gating.
  4. Kubernetes Documentation: Resource quotas — accessed 9 November 2026. Per-namespace limits on aggregate resource consumption and object counts for shared clusters.

Is a shared staging server slowing down your reviews and QA?

Tell us about your stack and pipeline. We will propose a preview environment design, with security and cost controls, that fits your team.