Trunk-Based Development in Practice
Before I get into how trunk-based development works for us, I’ll direct anyone looking for a comprehensive primer and argument for trunk-based development to this Atlassian article. This article compares the two primary development flows and gives the benefits for using a trunk-based development flow. It’s a really great article.
As for what a trunk-based actually means to us in practice, it depends on the size of the team. What works for a few developers would not work on a team with many developers. So we have two flows, depending on the size of the team.
Regardless of team size, the development items should be reflected in some way to cards/statuses in the project management system (e.g. Trello or Jira). So, for example, moving something to staging has two tasks: actually deploying it and actually moving the card to a list/status that means it is in the staging environment. And releases be communicated to the rest of the team. Communication like that is a constant across team size.
What is impacted by the size of the team, however, is the git branching flow.
Smaller Team
With only a few developers, coordinating staging releases is simple. So it’s possible and preferred to only have two core branches as that reduces overhead.
Branches
main
- Development mainline and staging environment base.production
- Reflective of the production environment.
Flow
- Pull Requests are based on
main
and point tomain
. - Staging releases are made off of
main
. - Production releases are made from
main
toproduction
via pull request merge.- It can be direct, or it can be from a deploy branch (a branch off of
main
or the target calleddeploy-MM-DD-YYYY
, for example). This allows pulling out commits or cherry-picking if necessary.
- It can be direct, or it can be from a deploy branch (a branch off of
Larger Team
On a larger team with say five developers, having only two branches can become problematic and hard to maintain. So to handle a larger team, the flow is altered to include a staging
specific branch to control staging releases and add an extra review step.
Branches
main
- Development mainline.staging
- Reflective of the staging environment.production
- Reflective of the production environment.
Flow
- Pull Requests are based on
main
and point tomain
. - Staging releases are made from
main
tostaging
via pull request merge. - Production releases are made from
staging
toproduction
via pull request merge.
Like with the smaller team flow, deploy branches can be used to deploy only a subset of commits.
Conclusion
There’s always improvements to be made to any development flow, but this is a flexible flow that has been tested across various projects I’ve been on. It allows for quicker merges and a way to see production deploys and what code is on production just from the VCS view. This, coupled with maintaining the mirrored view in the project management board, creates clarity over where a development item actually is (i.e. is it being worked on or is it ready for review on staging). I personally prefer this type of flow to the alternatives for its simplicity and flexibility.
4 Areas to Master for New Developers!
06/21/2021 - Jonathan Wang
Coming from a 16-week full-stack coding bootcamp, I learned a bunch of skills and technologies jammed into such a short time. I learned and used several modern programming languages, frameworks, databases and other important pieces of tech. I spent time...
First Year in Review
10/25/2021 - Sarah Sunday
It has been a little over a year since I officially started the business. Which means it’s time for a retrospective! This is going to be all over the place, which is where I’m at mentally right now. It’s not...