Trunk-Based Development
36 points by GarethX 5 months ago | 43 comments- jdlshore 4 months agoThis is content marketing for a feature flagging tool called “Bucket.” I’m a big fan of trunk-based development, although I prefer its original name: continuous integration. (Sadly, that name has been coopted by tool vendors.)
A better alternative to feature flags is keystone interfaces. It’s very simple: build your new feature without wiring it up to the UI (or API). Test it using automated tests that bypass the UI. When it’s ready, wire it up, manually confirm that the automated tests didn’t miss anything, and release.
- 0xbadcafebee 4 months agoNot that it makes a ton of difference, but technically trunk-based development refers more to the branching model, while continuous integration is a larger concept combining specific tooling, methods, branching, etc. You can do continuous integration with other branching models[1].
Unless a team tries hard to stick to strict CI, they usually end up with long-lived feature branches, long integration cycles, and clumsy, irregular deployments to irregular environments. So many teams still don't "get" CI, and end up wasting a shitload of time.
[1] https://www.martinfowler.com/articles/continuousIntegration....
- jdlshore 4 months agoThe article you referenced specifically says that “trunk-based development” is a synonym for “continuous integration.” Please see the section titled “What is the difference between continuous integration and trunk-based development?”
- 0xbadcafebee 4 months agoMartin's only saying that because the idea of CI came first, and he "doesn't want to rudely erase the work of Kent Beck". Trunk-based development has the branching model in the name. CI doesn't; it refers to a method to integrate code, and a whole lot of practices, tools, etc.
In practice, most people don't even use the trunk model for their CI. Most people use feature branches and PRs. They still use everything else from CI, except for the single-branch. What should we call that, then? Not-quite-CI CI? It's simpler to refer to the general idea as "CI", even if it doesn't use a single branch. If you want to refer to the strict single-branch method, "trunk-based development" makes it clear.
- kspacewalk2 4 months agoThat's a nice bit of history, but that is no longer common usage. Terminology has a life of its own, it isn't owned by those who first use it.
- 0xbadcafebee 4 months ago
- jdlshore 4 months ago
- tharkun__ 4 months agoNever mind the content marketing of the "article". Use whatever tool you want to. If all you have is `if env==dev|staging`, that's enough, no need for "Bucket" or whatever. In general terms though:
If you build your feature without wiring it up to the UI it means that you never integrate until the last moment. That way, you can't actually test a user interaction in an actually integrated fashion.
This is really bad, because you will find all the integration problems at the very last moment. Basically when you're about to give it to your customers.
Feature flagging combats that. It allows you to test the entire solution from the point of an actual customer, without exposing it to an actual customer.
- 0xbadcafebee 4 months ago
- hatthew 4 months agoI am strongly opposed to feature flags and conditionals in the code, unless absolutely necessary. If you don't remove deprecated features/branches, your code will end up unmaintainable. If you do remove them, the removal is (in my experience) worse than dealing with merge conflicts. Version control is designed for the exact problem of having multiple implementations exist and merging them as needed. Why roll your own obtuse version control by having all branches in the same file simultaneously when you can just use git to have them exist in parallel universes?
There's value in putting a newly completed feature behind a feature flag so you can turn it off instantly in prod. There is much less value in putting dozens of not-yet-functional features behind feature flags that shouldn't be turned on for the next several weeks/months (or maybe never).
- liuliu 4 months agoSo, I am not doing big development with hundreds / thousands engineers for quite some time. So I started to have sympathy to the other side of the story. The problem with feature branches, especially for frontend development, is that it is never just a "feature" (otherwise, you can gate it compile-time by just compiling out that feature module completely, or in nodejs terminology, treeshaking?).
It is a combination of some new UIs, some updates to some interfaces, some new capabilities to a new middleware and some new APIs to call backend. And you don't want to gate these behind a feature flag. And merging these into main branch while make sure when multiple person working on a feature branch know what commits they did on feature branch is in main branch and why a merge from main branch would just absorb these commits are tiring.
In these cases, trunk based development is really working for cases that not every developer is a git guru and can just navigate the merge back forth from main branch to feature branch and back. Yes, for these, subversion / perforce makes more sense, but everyone who is not git guru is still on git.
That coupled with inefficiencies of your CI system only runs on main branch and needs manual adjustment to run on a feature branch every time, it is easier to do it on the trunk.
Every problem is a tools problem, and people picks least resistance to make tools do what they want. There is no right or wrong, pick your poison wisely.
- vishnugupta 4 months ago> Why roll your own obtuse version control
This is exactly it. Feature flags sounds really good until one realizes that they have all the requirements of a version control. So much that it was even a running joke at Uber that one starts building feature flag and ends up with a version control.
The cruft of feature flag also makes it really hard to understand while reading a code, there’s a combinatorial explosion.
- sunshowers 4 months ago> Version control is designed for the exact problem of having multiple implementations exist and merging them as needed.
This is a common misconception! The primary purpose of version control is to answer discovery requests when the lawyers come knocking. :)
(I'm only half joking here. I do think VCS merges are generally not a good idea, for technical reasons like criss-cross merges being an issue.)
- prpl 4 months agoThere are tools that exist to clean up old flags, but of course you need to know they should be retired (if always off)or integrated into the baseline code (if always on)
- liuliu 4 months ago
- jtreminio 4 months ago> On top of that, once you finally get a feature merged and deployed, it can often happen that there’s a bug causing users to have a poor experience. Since your new feature lives directly in the code, deactivating it requires rolling back the code you merged, building it, waiting for the tests to run, and redeploying the application
Why aren’t you using feature flags to gate new behavior/functionality?
- ashenke 4 months agoThis is literally what the article advocates. It pushes things to the extreme where every code you write would be on the main branch and behind a feature flag
- ashenke 4 months ago
- js2 4 months agoEverything old is new again:
> Flickr is somewhat unique in that it uses a code repository with no branches; everything is checked into head, and head is pushed to production several times a day. This works well for bug fixes that we want to go out immediately, but presents a problem when we’re working on a new feature that takes several months to complete. How do we solve that problem? With flags and flippers!
- 20after4 4 months agoThe Flickr team was really innovative and the industry as a whole learned a lot from them. Perhaps some of that wisdom has been lost on the next generation of developers and now it's being packaged and sold to them.
- 20after4 4 months ago
- furyofantares 4 months ago> Trunk-based development is the seemingly radical idea of a team working together on the same code base at the same time.
Seemingly radical, hm. I've never worked any other way in 20+ years.
- zeendo 4 months agoEvery time this comes up it feels like two groups of people meet where one group either thought the other didn't exist or was much smaller than it really is. It's bizarre.
- roncohen 4 months agoAgreed! It’s apparently a divisive topic.
- roncohen 4 months ago
- weakfish 4 months agoI’m gonna be honest, this sounds horrible. If you do adopt this though, why even use Git? Why not use Perforce or something?
- kevmo314 4 months agoAs someone who uses this model with git, the main reason is because git is ubiquitous but I cannot get used to git's incredibly user unfriendly API. I've tried the feature branch approach and it doesn't click for me. Merge conflicts, lost changes, and git reset everywhere.
So in other words, I'm using this model because if I could use perforce I probably would, but git is everywhere.
Also, every time I bring up git's user unfriendliness, I'm always told it's not that hard and I'm holding it wrong. I'm sure I am now too, I just don't care.
- mamcx 4 months agoWith jujutsu I think is very close to allow this kind of stuff. I like branches because some of my work truly benefit from slow cooking, but with jj I'm more linear than before.
- weakfish 4 months agoI’m curious how you’re encountering merge issues. I have gravitated towards aggressively rebasing onto main, which has almost entirely solved this for me.
- kevmo314 4 months agoIf I'm only working on one feature at a time then actually it's largely ok, it's when I have to manipulate the commit graph that things start to really go wrong for me. But rebasing I still don't understand, even after using git for over 10 years. I mean, I understand conceptually what it's trying to do, but every time I run `git rebase` I end up in a crazy wild state.
For example, suppose I'm working off main and I have a new branch right off HEAD with five commits on it. I realize that oh actually I want to port this onto a different branch that was HEAD~5 with three new commits that aren't on main. When I run this, git suddenly seems to merge conflict a whole bunch of stuff unrelated to my commits (and are related to the three commits not on main) and it gets worse the further from main the relevant branch is.
What I really want to do is essentially take the last five commit diffs and apply them to the HEAD of some other branch instead, like how you might drag and drop the graph nodes.
Currently to work around me not understanding why git doesn't align with my mental model, I un-commit my changes, git stash them, switch to the target branch, create a new branch, and then git stash pop. This seems to work much more reliably but it's so tedious to do every time that I kind of avoid doing this sort of change as a whole.
- kevmo314 4 months ago
- mamcx 4 months ago
- kevmo314 4 months ago
- smithcoin 4 months agoHere is an article of how my team had accomplished this with GitHub actions I posted earlier: https://blog.gregweber.info/blog/github-actions-trunk-based-...
- twic 4 months agoI'd be interested to hear from anyone with substantial experience of trunk-based development who prefers a merge workflow, and can articulate why. Comments on TBD posts are usually either TBD enthusiasts, or people who have never used TBD and think it sounds stupid.
- tcoff91 4 months agoI have worked with trunk based development aka everyone just pushing change lists to perforce. I much prefer people making pull requests because I can make sure people fix things in code review before it gets merged to master.
I do absolutely hate however when someone works for 3 months on a mega PR and drops a +8000 -5000 on my head.
Ultimately both systems can work and both can suck.
- gregmac 4 months agoI echo this. No pull requests is awful. The only time it's worked well for me is with 2 or 3 people sitting next to each other, with the same mindset and coding style.
Every other time I've seen or worked with teams doing it, their codrle is, well, bad. It "works" but it is full of stuff half-done, "we'll clean that up later" - except it's been there for 3 years. And I'm looking at it because I'vr narrowed down a production problem I was called in to debug, that turns out to be crappy error handling with terrible logging that mislead everyone on what was going on. A proper PR should have flagged that and asked for something slightly better than logging "something went wrong" in an try..catch statement that spans many hundreds of lines of code.
Small, focused PRs are good. Easy to review, code gets merged fast, conflicts are minimized. Massive PRs are bad, they are hard to review (problems get missed) and slow to get approved. If they get reverted because of a problem it's a mess to fix. PRs that do multiple separate things (fix two unrelated bugs, add a feature, and reformat spacing in 30 files) are impossible.
If PRs are small and focused, the duration of time the branch is open, number of commits and the actual branching model does not matter.
Long lived branches are a pain to the author (they're who has to merge Main and resolve conflicts), but that's their choice.
- inetknght 4 months ago> I do absolutely hate however when someone works for 3 months on a mega PR and drops a +8000 -5000 on my head.
Trunk based workflow doesn't prevent that.
Moreover, heavy refactoring of code often ends up doing the same thing but much quicker.
- gregmac 4 months ago
- JTyQZSnP3cQGa8B 4 months agoTBD has merge requests. It lacks all the weird branches like hotfixes and goes back to a simpler set of branches. But MRs are still there. The author of the post is confused or is trolling on purpose of selling his tool. That is very dishonest.
- tcoff91 4 months ago
- sebazzz 4 months agoIt is really sad that almost no modern code review tools support trunk-based development. Nearly all tools assume some kind of branching/pull request.
One tool that was great for _both_ use cases was Jetbrains Upsource, where you could just string a bunch of related commits together in one review. Better yet, it could recognize based on the commit message (like workitem or CR number) that a commit belongs to the same code review and add it.
We actually still use it, even though Jetbrains canned it, because we have found no good alternative. Some of the tools that do code review mandate to also host the code within it, which is not an option because we already host the code in a system we’re happy with.
- losdanielos 4 months agoDo you do trunk-based development with Git? I'm just curious what the review tool would have to work with.
- losdanielos 4 months ago
- darthrupert 4 months agoAfter thinking about this for some time and weighing in with my 30 years of developer experience: don't do this. You will suffer.
Branches are there for a reason, and they are light-weight enough that you can use them even in a solo project. Everything will be easier if you flow with the tool instead of trying to fight it like this.
- jacknews 4 months agoThis looks horrible IMHO.
I agree changes to main should be kept small. But not too small. They should be coherent 'chunks' of functionality, even if they are not yet a fully working feature.
Committing to a dedicated separate branch, quite apart from protecting against fat-finger commits etc, keeps everything together, allows for easy code review of a complete, coherent change, etc.
- 4 months ago
- nativeit 4 months agoIt's things like this that make me fear we may have reached peak dev.
- stevage 4 months agoI wonder how you code review a half implement feature.
- darthrupert 4 months agoHow do you do code reviews with this model?
- roncohen 4 months agoIt’s in the post :)
> In practice, many teams will use a pull request-based workflow because the tests could be too complicated to run locally or need to facilitate code reviews. For trunk-based development to fulfill its promise, it’s imperative that pull requests are kept small and that the team is committed to reviewing them quickly.
- sebazzz 4 months agoThen it is not trunk-based, it is still PR based. I would also wonder how bigger features would get developed, without littering it across multiple pull requests and feature flags to make sure the code still compiles.
- sebazzz 4 months ago
- roncohen 4 months ago
- linkerdoo 4 months ago[dead]
- pluralmonad 4 months ago[dead]