Back to Blog

3 minutes read

Trunk-based development


During the third presentation at the year-end conference, our software engineer, Nikola Malinović, stirred the waters by delving into trunk-based development—a departure from the conventional Gitflow.

Trunk-based development represents a modern approach to software development that focuses on speed, reliability, and efficiency. Here, we will provide insight into its critical aspects and inspire you to consider this approach to optimizing your software development process.

Showing the Gitflow strategy

Gitflow is a widely known branching strategy among programmers, unlike trunk-based development. However, Gitflow comes with challenges such as numerous branches, complex branch management, multi-team coordination, and complicated releases.

Gitflow diagram example
Gitflow diagram example

Trunk-based development vs. Gitflow

The most significant advantage of trunk-based development compared to Gitflow is that it does not use “long-lived” branches. Here are some reasons why long-lived branches can be detrimental:

  • Delayed feedback
  • Stale code
  • Increased complexity
  • Merge hell
  • Extended time to delivery
  • Complex release management

More straightforward and more efficient

Trunk-based development generally proves to be simpler and more efficient than Gitflow, although exceptions exist.

Trunk-based development diagram example
Trunk-based development diagram example


Another important aspect of trunk-based development is CI/CD. A good CI/CD setup allows developers to be even more efficient by automating the deployment process.

CI/CD in trunk-based development

DEV environment

Here is an illustration of CI/CD in trunk-based development when it is deployed to a DEV environment:

Trunk-based development deployment flow for dev environment
Trunk-based development deployment flow for dev environment

As soon as a developer pushes changes to the remote git repository, the deployment pipeline should be triggered.
The pipeline may contain many steps. In the image above, we presented only a few essential steps. Additional steps that will cover specific project needs may be added. One noticeable thing is that there are multiple different test steps. These are essential since the QA team is absent in trunk-based development. It is vital to have good code coverage and different types of tests.

PROD environment

Here is an illustration of CI/CD in trunk-based development when deployed to a PROD environment: The deployment pipeline will be triggered as soon as a PR is approved and the feature branch is merged into the master branch.
The steps are similar to DEV deployment, but there is one catch. Everything gets deployed to STAGING first. If and only if everything works fine on STAGING (end-to-end tests are passing), then the application gets deployed to the PROD environment.
It is essential to understand that the Staging environment is used only as a pre-PROD step; therefore, it is important not to change anything manually on STAGING.
If any of the steps fail, the pipeline will be automatically stopped, and the changes will not reach PROD.

Trunk-based development deployment flow for production environment
Trunk-based development deployment flow for production environment

Trunk-based development with extensive features

Since trunk development is based on frequent and minor changes, it was essential to explain how to deal with extensive features. The answer to that question is “feature flags.”

The benefits of trunk-based development

Nikola concluded by highlighting the advantages of trunk-based development and shedding light on its key elements. These benefits motivate not only him but also others to explore this method for enhancing the software development process.

Trunk-based development offers the following advantages:

  • Continuous integration
  • Reduced integration complexity
  • Faster feedback loop
  • Improved collaboration
  • Easier bug identification and resolution
  • Parallel development
  • Quicker time to market
  • Feature toggles for controlled rollouts
  • Easier rollback
  • Smoother code reviews

Explore our blog section for upcoming captivating topics that we’ll be sharing with you soon.



Related posts.