How To Implement Trunk-Based Development? A Practical Guide

Trunk-Based Development is one of the most effective approaches in software development and can be a first step towards making the switch to feature management. Read this article to learn what it is and how it differs from how most engineering teams work.

What is Trunk-Based Development

Table of contents:

  • Why the standard approach to the software development process doesn’t work
  • Does software development have to be long and expensive?
  • Key benefits of using trunk-based development
  • Implementing Trunk-Based Development – best practices
  • Make code development even more efficient

Why the standard approach to the software development process doesn’t work

Before we explain Trunk-Based Development, let’s look at the standard approach typical for most development teams.

So, each developer creates a new branch for each recent change or feature. Then, when their component is completed and tested, it is merged with another branch of a lower environment (for example, dev or QA).

So, most of the time, the developer works on a small part belonging to a larger whole, and changes in the branch do not affect other developers on the team. Only after time is his code merged upwards and then into the repository’s main branch to deploy a new, bigger production release. This approach is called branch-based development or branching strategy.

Unfortunately, this way is usually inefficient, time-consuming, and expensive. It takes a long time to make each change, which can leave customers or users unsatisfied. What’s more, any bug in an application can cause significant downtime, and undoing the changes made is a complicated, risky and costly process.

Does software development have to be long and expensive?

As you can see, the abovementioned process can be inefficient and slow down the entire software development process. Fortunately, another approach allows you to develop software faster, more efficiently, and cheaper. And now, of course, we’re talking about Trunk-Based Development.

What is Trunk-Based Development?

In short, Trunk Based Development (TBD) is a software development process that involves a development team working in small batches and ​​merging their work into one main trunk.

The name comes from the concept of a growing tree, where the thickest and longest element is the trunk (master), from which thinner and shorter branches develop. The method involves delivering small changes and fixes that, when completed, go straight back to the master. It means that releases come directly from the master branch. In this practice, the IT team tries not to create branches or maintain them for a maximum of one day. At the end of each day, work from all team members is merged into the main branch, which is merged upward.

With this method, developers don’t waste time and energy on tiresome code merges or broken builds, and the code can be continuously improved. And what about the code quality? Well, adding automated tests and test code coverage metrics to the Continuous Integration process ensures that incoming changes have high-quality assurance.

Key benefits of using trunk-based development

Trunk-Based Development is a prevalent method that has many followers around the world. What is its phenomenon? Here are the most important benefits of this practice:

Adding changes quickly and efficiently

The trunk-based branching strategy continuously merges changes into the main branch. There are no long-lived feature branches to maintain and resolve conflicts. By implementing small changes, development teams avoid the risk of unexpected bugs or integration issues. Software developers can focus on creating code rather than making merges and fixing bugs.

Easily deploying new software versions

Trunk-Based Development is a method that works well not only for implementing small changes. When the IT team works on new software versions, they are also developed from the trunk, and different versions on environments can be deployed at will. Importantly, you don’t have to switch changes between branches to deploy new code to production.

Smaller and easier Code Review

Small changes are more accessible for code review. When you follow this practice, only a few or a dozen files are changed in the code. As a result, the development team can focus more on the code, identify bugs faster, and easily improve code readability.

One codebase for testing

When working in a Trunk-Based Development model, developers typically work on one software codebase, which is tested and deployed to production. New ones can be turned on or off using so-called Feature Toggles or Feature Flags, still based on a single code base. With this approach, the team can minimize the number of test environments and focus on only one or a few of the most stable ones.

Ability to introduce a CI/CD process

In a trunk development model, you can easily introduce a fast software release cycle through a Continuous Integration (CI) and Continuous Deployment (CD) process.

After the changes are sent to the main branch, automated and quality tests will follow, and the application can be deployed to the test environment. In the next step, the development team can decide to deploy the changes or automatically send them to production. If you want to opt for the second option, you must remember to provide an easy and fast process for rolling back changes.

Increase speed and frequency of delivery

With a strategy based on small continuous deployments, the clients or users do not have to wait long for the changes they need. The development team can regularly deploy new updates without creating large, complicated ones. 

What’s more, if you’re not sure if users will well receive the changes, you can make them available to selected customers for early feedback. If the changes don’t work out, you can quickly withdraw them.

Implementing Trunk-Based Development – best practices

What can you do to ensure your trunk development implementation achieves the best results? Here are some proven practices that will bring you the most important benefits.

Implement automation

First of all, you should implement automation wherever it is possible and effective. It can involve software development, testing, and deployment. This approach will allow your team to perform fast and efficient iterations, minimizing the risk of damage to the main branch.

Use pair programming or mob programming

In Trunk-Based Development, code review should be done immediately. Moreover, automated testing will not always ensure good quality code, so it is worth using techniques such as pair programming or mob programming to improve team communication and allow real-time code review. The benefits of these solutions are great, as they not only affect the quality of the code, but also help integrate the team and enable the valuable exchange of knowledge. The last one is especially important if you have juniors on your team.

Try a feature flags management tool

Feature management is a technique for managing the feature development and testing process. It allows you to gradually release changes or new features to selected user segments before the entire software is deployed. The practice applies a technique called feature flags that enables IT teams to wrap new changes or features in an inactive code path and activate them at any moment.

To make this process as easy as possible, it’s worth using off-the-shelf feature management software such as Unleash. This tool allows you to experiment with features and A/B tests to determine which version best meets users’ expectations. Moreover, the platform also enables continuous deployment of microservices, so developers can combine testing with feature deployment.

All features are deployed without affecting the stability of the software, and your team can easily roll back any feature without affecting the rest of the software and without risking damage to the code in production.

Make code development even more efficient

Trunk-Based Development (TBD) is a well-known and efficient method used by technology giants such as Facebook, Google, and Netflix. According to the Accelerate State of DevOps 2021 report published by Google: high-performing organizations are more likely to have implemented trunk-based Development.

However, for this method to bring the best benefits to your company, you must ensure that you follow best practices.

If you want to make code development and change management even more efficient – try Unleash. Our simple and intuitive platform lets you choose which users have which features. You can use multi-variant feature flags across multiple environments, applications, and services.

To use feature flags, all you have to do is toggle them on (on) or off (off) with the toggle switch. What’s more, you can enable the feature for specific groups of users, such as users with specific IP addresses, hostnames, and others.

Don’t wait and check out our feature management tool today.


Share this article