Preview Environments per PR: The Setup That Pays Back Quickly
Preview environments make every PR demo-able and every reviewer effective. The setup is one-time; the dividend is every PR.
Why preview environments
Code review on a static diff misses behaviour. A working preview environment per PR catches regressions and UX issues at review time, not after merge; the dividend is every PR.
- Behaviour beats diff. Reviewers click around the actual feature; subtle UX issues surface that the diff hides.
- Catches earlier. Issues found at PR review cost a fraction of issues found post-merge or in production.
- Reduces back-and-forth. One review cycle vs three; the team's velocity improves measurably.
- Demo-ready. Stakeholders click the preview link, see the feature, give feedback before merge.
Four implementation components
- 1. Per-PR namespace in Kubernetes.
- 2. Per-PR DNS via wildcard SSL.
- 3. Seeded test data per env.
- 4. Auto-teardown on PR close/merge.
Cost control
Preview environments at scale need cost discipline. Cheap nodes, shared infrastructure, quotas; the controls keep the bill reasonable.
- Spot/preemptible nodes. 60-80% cheaper than on-demand; preview environments tolerate eviction.
- Shared data layer. Point at a shared dev DB; per-PR data clones blow the budget at scale.
- Per-team quotas. Max N preview envs per team; oldest auto-evicted when at the cap.
- Cost dashboard. Per-team preview spend visible; the team self-tunes once it sees the numbers.
Lifecycle discipline
Auto-teardown is the discipline that makes preview environments sustainable. Without it, envs pile up to hundreds and the cost explodes.
- Auto-teardown on close. PR closed or merged triggers immediate environment cleanup.
- Idle pause. Envs idle for over 48 hours auto-pause; restartable on demand.
- Idle delete. Envs idle for over 7 days auto-delete; nudge the engineer first.
- Surveillance. Quarterly review of orphan envs; rules tuned based on what slipped through.
Antipatterns
- Per-PR full data clone. Cost explodes.
- No auto-teardown. 200 idle envs by quarter end.
- Production-equivalent for previews. Wasteful; previews are dev-tier.
What to do this week
Three moves. (1) Apply this to one pipeline first. (2) Measure deploy frequency / MTTR before/after. (3) Document the outcome so the next team starts from data.