What are preview (ephemeral) environments?

IntermediateConceptCI/CD practices
Answer

In one line: Preview environments are temporary, complete copies of an application created automatically for each pull request, so reviewers can test the change live — and they are deleted when the PR is closed.

How they work:

  1. A developer opens a PR.
  2. The pipeline builds an image for the PR and deploys it to a new environment, for example a Kubernetes namespace pr-142 with a URL like pr-142.preview.example.com.
  3. The pipeline comments the URL on the PR.
  4. Reviewers, QA and product managers try the change in a real running app.
  5. When the PR is merged or closed, the environment is destroyed automatically.

Benefits:

  • Faster, better reviews — people test behaviour, not just read code.
  • No fighting over a shared staging environment.
  • Catch integration problems early.
  • Demo features to stakeholders before merging.

How teams build them:

  • Kubernetes namespaces + Helm, created by the pipeline or by Argo CD ApplicationSets with a pull-request generator.
  • Platform features: Vercel and Netlify previews for front ends, Heroku Review Apps, GitLab Review Apps.
  • Terraform workspaces for heavier infrastructure (slower and more expensive).

Challenges:

  • Cost — limit resources, auto-delete after a timeout, and scale to zero.
  • Data — use seed or synthetic data; a small shared test database or a per-PR database copy.
  • Dependencies — decide which services run per-PR and which are shared.
  • Cleanup — make sure environments are really deleted, or cloud bills grow.

Example: an Argo CD ApplicationSet watches open PRs labelled preview and creates an app for each one in its own namespace; closing the PR removes the app and namespace.

Tip for interviews: mention cost control and automatic cleanup — that's what interviewers look for after you explain the idea.

All DevOps Fundamentals questions

More on CI/CD practices