r/devops • • 17d ago

Discussion Do branch preview environments actually make your workflow better?

I have been thinking about how to test changes without constantly messing with the version of my app that everyone else is using. Right now I usually test locally and then push changes when I think everything is ready. Separate preview environments seem useful, especially when working on a feature that takes a few days, but I am not sure how much extra setup and cost they introduce. Do you use them for smaller projects or is that more of a team workflow thin

23 Upvotes

28 comments sorted by

19

u/s33d3r 17d ago

Argo CD ApplicationSet PR generator fits the bill nicely. We use it a lot. Crossplane / ACK manages infra deps.

14

u/the_frisbeetarian 17d ago

We use preview environments at a pretty large scale. They are a pain in the ass to maintain, at least the way we are doing them, with the requirements that we have. I am a bit old school and definitely prefer developing as much as I can locally.

4

u/donjulioanejo Chaos Monkey (Director SRE) 17d ago

Same. Ours use push-based deploys and a helm wrapper, so you need shell scripts for some specific apps to make them work to template out environment variables before booting. But they work really well, popular with devs and QA, and let us do some extremely extensive testing before anything makes it into production.

Especially useful for building integration between all the multiple apps and microservices we run.

13

u/hard_KOrr 17d ago

1 non production feels pretty mandatory for anything people rely on.

5

u/EirikurErnir 17d ago

I'd say having a consistent way to verify that what you're about to put live actually works is mandatory, but I don't think that necessarily includes a non-prod environment

1

u/hard_KOrr 15d ago

Yeah it’s not just about verification either, having an environment to debug or thrash. “Works on my machine” doesn’t help anyone.

4

u/elitesense 17d ago

The only "shared" non prod environment we have is a staging environment that represents prod as-is + any upcoming changes reviewed and merged... staged for the next release to prod.

For active development environments (like you're talking about), things like testing new features before delivering, are mainly tested locally, spinning up services (and seeding data) using shared tooling to help developers spin up what they need to see things work locally. This is dynamic, and ever changing, unlike the established shared non-prod environment.

2

u/Flabbaghosted 17d ago

For a smaller project it's not necessary but is probably a good introduction to how a larger company will operate. Lots of managed resource in cloud companies will have slots or preview features for little or no extra cost. It's smart once you start having features that aren't easy to mock with tests or locally or for practice. But for a hobbyist it's overkill

1

u/Washyourmouth95 17d ago

I've been trying to keep my setup simple, so I get why people use preview environments. Some platforms handle this pretty well, and Light Cloud is one option where each branch gets its own URL. The previews only bill while someone is viewing them, which seems useful if you're not constantly testing changes.

1

u/Forward-Outside-9911 Linux Sysadmin 17d ago

Preview environments are great. It depends heavily on what infrastructure you use and if your provider offers it natively.

I built a basic system on K8s to create preview environments on PR open, then stop the containers when not being used to save resources.

But if you use a managed provider they may even have this built in. 100% worth it.

1

u/Iyemoja 17d ago

Yes, once a feature takes more than a day. A preview link saves the whole team from the classic it worked on my machine at 2am argument.

1

u/Geraldwelly 17d ago

For a solo project I'd skip per-branch environments and keep one staging environment that mirrors prod, deployed from whatever branch you're testing. That gets you most of the benefit for one extra box. Per-PR previews start paying off once two people step on each other in staging, or when non-devs need to click through a feature before merge. On Vercel, Netlify or Render they're nearly free for the frontend; the database is where the cost and pain actually live.

1

u/LieutenantNitwit 17d ago

I've got a bare metal box stood up with a self hosted runner to help mitigate github's bullshit. Spins up on average 20 isolated envs per day. ZFS is the secret sauce. Isolated envs with 11 containers each spun up in around 2 minutes (if you keep the ZFS data fresh like weekly or some shit). The box is indispensable for ops where I am but we have a large team with frequent deployments. Prolly overkill for smaller teams but I'd definitely look into self-hosted runners and ZFS for preview envs.

1

u/Cozy_Cloud_Club 17d ago

They can, but for a smaller project I wouldn't start with a preview per branch. A single shared non-prod environment is usually the piece that's actually missing if you're testing locally and then pushing. That's enough to catch deploy and config issues without paying for five copies of the stack.

Per-branch previews start to pay off once more than one person needs to look at a change, or a feature sits around for days and would otherwise block that shared environment. The cost people worry about is usually the idle ones. What's worked for me is tearing them down when the PR is idle or merged, rather than leaving them up all week.

The part that surprised me more than compute is the data. If the preview needs a realistic database, auth, and callbacks, that setup work is most of the effort. I wouldn't copy production data into them. For a small app, I'd get one durable staging environment solid first, then add ephemeral previews only when the shared one starts getting in the way.

1

u/themanwithanrx7 17d ago

It was already fairly nice to have pre-agentic/ai coding. These days its even nicer since I have more non-tech people submitting changes

1

u/EditorPrimary 16d ago

I think having multiple environments is necessary to test changes before releasing them. Ideally, we should have regression tests to make sure existing features and previously fixed bugs still work as expected.
The problem is that as the test suite grows, running everything becomes a bottleneck. So instead of running all tests every time, we should only run the ones relevant to the changes.
In the past, this usually meant a bunch of if-else rules or developers manually picking tests. But with LLMs (Opus, Sonnet, or even JEV), we can build a script to analyze the changes and automatically select the relevant test cases.
We can still run the full test suite nightly to catch anything we might have missed.
I think this makes the most sense right now: keep the feedback loop fast while still making sure our changes don’t break existing functionality.

(sorry for using AI to translate, I’m not native)

1

u/arw0n8236 16d ago

I would say it is almost mandatory. In mye experience, many devs will code in a way that breaks k8s best practices (no file writing access, strict network policies, non-root user), so catching those in a dev/staging environment is really valuable.

I've worked mostly with a prod/staging/dev/(demo) split so far, but on a large project with multiple teams I also dynamically generated environments for long-lived feature branches (I think if you expect a feature to take more than 6 weeks to go into prod it makes sense).

Since you are a solo dev, I would recommend a development environment where you can test changes before hitting prod, but you can also get 85% of the way by having a local setup with docker that mirrors your server infra as much as possible.

1

u/BetterSWE_Official 16d ago

the part people skip is the data. spinning the app per branch is easy, the database isn't. if every preview points at one shared db you pay for the setup and still step on each other. on a small project id get a seed script that builds a fresh db in a minute before worrying about per branch anything

1

u/Chamelon_DE 15d ago

The database is the part worth planning earl, does each preview get its own data or share a test database?

1

u/Senior-Assumption864 15d ago

for a small project i would start with one staging env and only add per branch previews when it starts to hurt

1

u/PatienceWeekly1639 14d ago

For me, yes, once the setup is automated. Before that they're a pain.

The big wins are that reviewers can click around instead of pulling the branch, and long running features don't block the shared staging env. Even solo, it's nice because it catches "works on my machine" stuff before merge.

Cost and setup are manageable if you do a few things:

  1. One environment per pull request, created by CI and destroyed automatically when the PR closes or merges.
  2. Add a TTL or nightly cleanup job, because orphaned previews are where the bill sneaks up.
  3. Keep them small. Tiny instances, scaled down, shared services where it's safe.
  4. Be careful with the database. Seeded or throwaway data per env, never prod data.

If your app is a simple web app, hosting platforms like Vercel, Netlify or Render do previews out of the box, so you don't need to build anything. For anything heavier I'd start with just the frontend and add backends later.

0

u/freeo 17d ago

I use DEV, INT, PROD by default. Local too, but that mostly doesn't count, although I plan to improve here too, but purely for agent swarms. DEV for regular development, full system, high velocity, alwyas 'broken'. INT: Where other people get to see things, main purpose: testing the deployment itself, all upgrades, see how an env behaves after big changes - this one is critical, especially with agent development. Not even 5% of INT deployments make it into PROD. This one keeps me sane. Heard about more complex CI setups which make this redundant. But I choose less complex CI, but more environments. My CICD is simple, plain stupid gitops with FluxCD, no custom stuff. Environments are the better bin for complexity in my experience. More ad-hoc environments might become hard to manage though. 3 is my optimum, cost/benefit wise, in a rather small system, btw.

-1

u/[deleted] 17d ago

[removed] — view removed comment

1

u/Forward-Outside-9911 Linux Sysadmin 17d ago

They’re only running while you need them, a few hours per PR isn’t too bad.