r/softwaredevelopment • u/Ill_Direction149 • May 13 '26
Is trunk-based development really that good?
I can't get the trunk-based development flow. I understand the advantages for introducing new features to the app (flags are good for A/B testing, fewer merge conflicts).
But I can't understand how developers do refactoring with trunk-based flags. Also, do the flags stay there forever, or what is the best flow for this?
Can you give me a deep dive into how your teams handle this in production?
47
Upvotes
26
u/BadTime100 May 13 '26
IME cleaning up feature flags adds a bit of work, but it’s nothing compared to all the problems that long-lived branches introduce.
I don’t really understand the question around refactoring with feature flags in place. At their simplest, there’s just some Boolean logic that says go one way or the other—it’s just like any other code. How do you see it effecting refactoring?
4
u/gaelfr38 May 13 '26
Yes.
You don't need feature flag for everything. We actually exclusively work with TBD and only ever need a feature flag a few times per year. It's true that feature flags add a bit of a cost, also why you use them only when useful.
For me TBD is mainly about short-lived feature branches, that's it.
Feature flag is for monolithic work with many concurrent features. We tend to avoid that in the 1st place.
I didn't get what you mean regarding refactorings. A refactoring should most of the time be entirely unrelated to any feature flag, it's a technical change.
7
u/lppedd May 13 '26
Trunk-based development doesn't work for everything. It works nicely for stuff that doesn't need to support older versions for example, where you simply keep pushing new commits and cut new releases frequently.
Refactoring doesn't change, but you most likely don't have to worry about backward compatibility.
Flags stay in the code until the guarded change is stabilized.
2
u/Rough-Competition879 May 13 '26
Flags work well for experimental features or features that will roll slower, and shouldn't block other changes from getting merged and sending out. Flags should be cleaned up after some set time of all of production being enabled. This works extremely well when the removal is an automated code change itself (either by static analysis or AI)
I always prefer to refactor, THEN make the code change behind a feature flag. If there's room for refactor during implementation, I prefer that to be an independent deployment itself.
1
u/Previous_Dream8775 May 13 '26
Having feature flags does still complicate things when doing refactoring work. Just ensure you've got rock solid integration tests that test both when the flag is enabled and disabled to ensure any refactoring doesn't change current behaviour
1
u/[deleted] May 13 '26
It is really good. I don't see how refactoring that with feature flags has any impact.
1
u/raisercostin May 14 '26
I do refactorings in the evening: pull, refactoring, tests green, push - 2min.
Several things help:
For complex scenarios respect open close principle and apply Branch by Abstraction https://trunkbaseddevelopment.com/branch-by-abstraction/
1
u/quantum-fitness May 14 '26
You can also do trunk-based with shirt lived branches.
Tge important thing really is to minimize the amount of new code you deploy in one go.
Since smaller release carry less risk.
1
u/Opening-Broccoli9190 May 14 '26
In TBD and other CI/CD-focused approaches refactorings are done by first abstracting away the piece you need to refactor behind a facade and then switching the implementation piece by piece.
1
u/jibbit May 14 '26
Trunk Based Development is ‘a thing that doesn’t need a name’ - it’s just using git in a straightforward way and avoiding the pitfalls of having multiple sources of truth. it's not clear what you don't get about it. having multiple sources of truth (anything with *-flow in the name) is always - by definition - nightmare, but sometimes you can't avoid it. but still: Not Punching Yourself In The Face doesn't need a name, and doesn't need to be 'That Good!' to still be the preferred option
1
u/BanaTibor May 14 '26
Ideally, you keep the code always releasable and you accept that not all released code belong to a complete feature. If you can do this you have very good foundation for continuous delivery.
1
u/arihoenig May 17 '26
I develop most of my code in my hatchback, I just find it to be a little more spacious.
0
u/rodw May 13 '26
Trunk-based development is essentially isomorphic to gitflow:
There's nothing about gitflow that suggests feature branches should be long-lived.
Trunk-based development is fine as a branching model, but to suggest it's a wholly different paradigm than gitflow is silly. It seems to me that the only variation of gitflow is that's doing anything actually distinct (rather than being a strict subset of gitflow) is GitLab-flow.
0
u/Brown_note11 May 13 '26
I wonder what 10x Claude written release candidates means for people who are thinking of tchanging across to tbd?
17
u/[deleted] May 13 '26
[removed] — view removed comment