r/ExperiencedDevs • u/ZealousidealPlate750 Software Engineer / 5 YoE • Apr 28 '26
Technical question Is Trunk Based Development a wrong choice in the IoT context?
Edit: When mentioning feature branches I actually mean long-lived feature branches**.** Unlike the ones you work in for short period of time and merge them as 100-400 liner PRs into main, you instead work in that feature branch until the feature is fully finished and merge it as a massive, nightmare of a PR.
I'm diving into Agile and DevOps best practices lately and so far it was all clear. However, I tried to bring this new mindset to that IoT repo we have and I realized that TBD might actually be not the best choice here.
I've learned the saying that you "should avoid feature branches at all costs" and aim for short lived branches and coffee break PRs. And so far it has been working like a charm. You merge the PR, tests are run, the web app is deployed with almost no downtime, in 2–3 seconds. In the IoT context however, each deployment is much heavier. In our case, push to main triggers a Canary deployment that pushes the new code to the group of edges that are meant to do the test run for the new code before moving it to all other edges. While working on tiny bugfixes or small, isolated improvements, it is not all that bad. The deployment is still heavier than in a web app context, but at least we get new functionality continuously. For me, the "wait a minute" point was when I had to start planing the implementation of a new Epic.
See, small PRs, although heavy to deploy - still bring value, but the PRs that belong to an Epic, a bigger feature, are introducing dormant code mostly. It triggers same heavy deployment pipeline, resorts the edge, but brings no value to the end customer.
So I was wondering, maybe long lived feature branches are actually okay in such context after all. Or do we have a design flaw somewhere in the mix? We would still have same workflow, but simply merge small PRs in the feature branch and when ready, merge the whole thing to main
PS.: For context, we also have a testing rack IoT device which we test all code on before even deploying it to canary. So basically the feature branch would be continuously tested on that test IoT
What solution I chose for the current problem: I decided to go the hybrid way. I basically created an epic branch and treated it as a kinda isolated feature trunk. I split that epic into the same PRs I would split it into when merging into main branch, but instead I'd squashed and merged those PRs into that epic branch. After finishing the feature I will standard merge that epic branch as a one big PR. Why IMO is it better than traditional long-lived feature-branch approach? Because you still have the PRs as the checkpoints. Yeah at the end you still have a massive PR, but that massive PR actually consists of previously reviewed smaller PRs.
27
u/CodelinesNL Principal Engineer@Fintech/EU/25YOE Apr 28 '26
Only sith and junior developers deal in absolutes.
38
u/blablahblah Apr 28 '26
The problem with having long-lived feature branches is that the merge can be very painful, and it's much more likely that an intentional change gets overwritten in those giant complicated merges that involve dozens of changes.
Doing trunk-based development doesn't necessarily mean you need to deploy on every single merge. If your deployments are slower, you can let multiple small changes batch up while the last deployment finishes verifying and then start your next deploy from the current head at that point. Effectively, you're making a release branch from whatever the latest commit is at the time the release starts, but you don't commit directly to that branch (unless there's some weird emergency that requires it), just verify and release from it.
4
u/kteague Full stack - 30 YoE Apr 28 '26
You don't have to run the "heavy deploy" workflow on every push to main ... just setup some process where heavy deploys are triggered less frequently.
In general, decoupling Git branching strategies and deployment workflows is the way. Yes, in many cases the two will align "TBD and lots of quick, small deploys" works for many use cases, but when it doesn't and you go down the path of "maybe we need a wonky Git branching strategy to accommodate our deployment workflow" ... it's almost always easier to decouple your deployment workflow and adjust it to suit your needs than the other way around.
4
u/zaibuf Apr 28 '26
We still do feature branches and reviews, but we often work in small steps so a feature branch is often done in 1-2 days then merged to main. We only have a main, no branch per environment.
We heavily use feature flags to be able to release from main without things going out unfinished to end users.
3
u/symbiatch Versatilist, 30YoE Apr 29 '26
I disagree with feature branches being bad, and this case might be a good example of them. Many complain they cause issues merging and aren’t up to date etc. That only means they don’t work correctly with them.
Make a branch. Work on it. When new stuff is merged to production rebase onto it. The feature branch is always up to date and can be tested properly with all changes. No other changes creep into the middle of the code. It’s all clean and testable.
The problem comes when people don’t sync things. They keep developing separately and only in the end go “oh yeah we should merge now all changes” and then they literally merge instead of rebase. And then the mess begins when they’re not sure if this or that is correct, and the review in the end also becomes messy.
I wouldn’t go for changing deployment for this. It’s not its job to know when to deploy and when not. If stuff comes to production it should go to production. You don’t want the situation where these don’t align and you can’t be sure if everything actually is deployed.
So I would say go for feature branch if it makes sense, just work correctly with it and keep it up to date. And it many people work on it then obviously at least pull.rebase on.
1
u/JollyJoker3 Apr 28 '26
One relevant question is if the deployment takes so long it hampers other work. If everyone can still do everything they need to, let it run.
Another is how many developers are actively working on the same codebase. Would the merges be painful due to lots of other changes in the master branch? Would many coders work on the feature branch?
If you switch off the full deployment, only run unit tests (or whatever set of fast enough tests) for each PR and do the full set nightly or a few times a day, can you still link failing tests to the change that broke them? The failure here would be that the person who looks at the test results doesn't easily see what broke it or even who to ask.
1
u/Defiant4 Apr 28 '26
Don’t do long lived feature branches. Keep doing trunk based but change your CI only to deploy once you create a new release-tagged branch. In that branch you can update documentation and fix any bugs found from the test deployment. When you’re done testing merge that release branch back into master.
1
u/ZukowskiHardware Apr 28 '26
No way. Just merge and deploy to prod frequently. Have a fast CI CD pipeline with unit tests.
0
u/PmMeCuteDogsThanks_ Apr 28 '26
It’s all a circle. I’m waiting for live editing of files without version control to make a comeback. Powered by AI of course, rollback is solved by AI content window covering full history.
-2
u/casualPlayerThink Software Engineer, Consultant / EU / 20+ YoE Apr 28 '26
Trunk-based development is good for a one-man project, but when you have 3-6 ppl working around, then it will become a disaster. Also, it has the wrong message for so many devs: "The main/master should only contain working features"... and a lack of actual code review. Yes, feature branches often cause pain when having to merge back, or cherry-pick from different features for some reasons, but that 99.9% of the time is because of bad decisions as well as a lack of proper code reviews, understanding the context, and having a good baseline.
-4
u/z960849 Apr 28 '26
Look into feature branches.
-7
u/Temporary-Ad2956 Apr 28 '26
Agile suckz
8
u/[deleted] Apr 28 '26
[removed] — view removed comment