Problem
A single shared staging environment becomes a bottleneck: teams queue for it, changes collide, state gets polluted and nobody trusts results. Defects found there cannot be attributed to a specific change.
Also known as: preview-environments, review-apps, per-pr-environments
Create a full, isolated environment on demand for each change and destroy it automatically when the change is finished.
A single shared staging environment becomes a bottleneck: teams queue for it, changes collide, state gets polluted and nobody trusts results. Defects found there cannot be attributed to a specific change.
An ephemeral environment lives only as long as the change it validates. Each pull request gets its own copy of the application and its dependencies, reachable at a unique URL such as pr-482.preview.example.com.
CI or a GitOps controller reacts to pull request events. It renders the same templates as production with small overrides for size and hostname, creates a namespace, deploys, runs smoke tests, and comments the URL.
PR opened --> create namespace pr-482
--> deploy branch image + seeded db
--> run e2e, post URL
PR updated --> redeploy
PR closed --> delete namespace, db, DNS
(nightly) --> reap anything older than 3 days
Cost control comes from small replicas, scale-to-zero when idle, shared lower-tier services where safe, and hard quotas per team.
Medium - on-demand compute that scales with open pull requests
Medium - reaper jobs, quotas, seed data upkeep
Medium - environment parity and dependency mocking
Orphaned environments run for weeks after teardown fails
Environment shares a production database or third-party account
Provisioning takes so long that developers stop using it