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:
- A developer opens a PR.
- The pipeline builds an image for the PR and deploys it to a new environment, for example a Kubernetes namespace
pr-142with a URL likepr-142.preview.example.com. - The pipeline comments the URL on the PR.
- Reviewers, QA and product managers try the change in a real running app.
- 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.
More on CI/CD practices
What is "pipeline as code", and why is it better than configuring pipelines in a UI?BeginnerWhat is a build agent or runner?BeginnerWhat are pipeline triggers?BeginnerWhat is a quality gate in a CI/CD pipeline?BeginnerHow do you make a slow CI/CD pipeline faster?BeginnerWhat are secrets in CI/CD, and how should they be handled?Beginner