Trunk Based Development is a popular software development model used by the development teams of some of the biggest companies in tech, such as Apple, Amazon, and Google. It’s also the go-to mode of development for DevOps teams in the industry for delivering fast & high-quality software products. What is TBD, and why is it so popular? We’ll answer all of that and more in this article. Let’s begin!
The Basics of Trunk-Based Development
TBD sees developers working inside a single code repository that stores all the code for a project. Developers make frequent small, incremental changes as opposed to infrequent and large changes at once. Other developers constantly review code to ensure code quality and maintain standards set for the project until its completion. When errors arise, or new features get introduced, developers can quickly make changes and edits to the main branch without any issues. This style of development also largely helps to avoid issues like merge conflicts and keeps code constant stability and deployability.
Trunk Based Development is a key component of Continuous Integration/Continuous Delivery.
CI/CD is a software development methodology that focuses on quick & frequent code changes, code testing, and deployment of software. The main branch nature of TBD is one of the key factors that enables CI/CD to be effective in its application. Other factors, such as frequent small changes, code reviews, and automatic testing, also play a role.
The styles of TBD
Generally speaking, there are two different kinds of TBD, and they are based on the size of the development teams. For smaller development teams, changes tend to be committed to trunk. For larger development teams, they use smaller branches as opposed to a unified main branch to make changes.
Pull requests in TBD
Pull requests are another key part of TBD. Pull requests in TBD are sets of changes to the source code that developers want to merge into the trunk. Anytime a developer makes a pull request, it must go through a manual review process from other members of the development team to ensure no new bugs or errors are introduced. In addition, pull requests are also automatically tested as an extra layer of quality assurance.
TBD best practices
We’ve talked a lot about what Trunk Based Development is, but what are some of the best practices for its implementation? Let’s have a look.
➡️ Small & frequent patches of development
As mentioned earlier, one of the main features of using TBD is developers making small but frequent changes to the main branch. Developing in this way reduces the likelihood of merge conflicts and other errors slipping through the cracks during a development cycle, allowing teams to make changes and release new updates or features with confidence.
➡️ Code Reviews & Automatic Testing
The frequent changes made when using TBD must always be reviewed before they are committed. This is where code reviews and automatic testing come into play. Code reviews are conducted manually and by each member of the development team to ensure that all changes are valid. On top of code reviews is automatic testing. Automatic testing makes sure no changes committed to the main branch break the project’s codebase. Integration testing, end-to-end testing, and unit testing are the most common automated testing tools developers use.
Advantages of Trunk-Based Development
We know that TBD is a popular way of product development, but why? What are its benefits? Let’s explore a little more in some detail.
✅ Fast feedback & constant collaboration
The small and frequent changes made while using Trunk Based Development see development teams constantly communicating and giving back feedback. This is because all changes get made to a main branch, which requires both a manual and automatic review process before being accepted.
✅ Easy integration & maintenance
TBD sees developers using a single codebase for a project, a feature of simplicity that cannot be understated. Bug fixes, code reviews, and code refactoring are made easy because all errors are found on a single main branch. Integration and deployment of new features becomes seamless because committed changes are always ready to go.
Disadvantages of Trunk-Based Development
Now that we understand the upsides of using TBD, let’s take some time to understand where TBD may be a disadvantage for development teams.
❌ Codebase complexity
Although TBD simplifies developer collaboration with a single codebase, there is a risk that it can grow in complexity. As a project grows in size, so does the size of its codebase. Large codebases are difficult to maintain and contribute to without errors. They come with longer build tests and times, as well as a higher risk of breaking the main branch.
❌ System dependency
While not unique to Trunk Based Development, outside systems and libraries can have an effect on the development of a project. Many projects depend on third-party libraries and systems to function, and changes to these libraries are outside a development team’s control. Critical changes have the potential to doom a project either during or after its development.
Putting it all together ❤️
TBD prioritizes team collaboration, quick iteration, sustainability, and high-quality delivery of software. By using a single codebase for development, developers avoid the issues and complexities that come with branch-based development. TBD also promotes transparency and team-building by encouraging developers to share code and communicate frequently. For teams that want to optimize their workflow while delivering the highest quality product possible, it doesn’t get better than Trunk Based Development.
Looking to automate your GitHub workflow? Mergify has everything you need. Try our workflow automation tool for free!