Coastal Media Brand

Trunk-based development first emerged in the early days of version control systems and agile methodologies. The term gained prominence with the advent of distributed version control systems such as Git. Similar to agile, trunk-based development emphasizes the continuous delivery of a working software.

As a product manager, implementing trunk-based development into your software development life cycle enables you to reduce complexity and achieve faster time to market.

In this article, you will learn what trunk-based development is, its key principles and practices, and the challenges that may emerge.


Table of contents


What is trunk-based development?

Trunk-based development is an approach to software development where developers frequently integrate their code changes into a shared main branch, called the trunk or mainline, instead of working on long-lived feature branches:

Trunk-Based Development

Benefits of trunk-based development

Trunk-based development offers several benefits that contribute to improved software development practices. Here are some key advantages:

  1. Continuous integration — Trunk encourages continuous integration, where developers frequently merge their changes into the mainline. This approach ensures that code is regularly integrated, helping to identify and resolve integration issues early in the development process, which reduces the risk of large and complex merges and enables teams to catch problems sooner
  2. Team collaboration — Developers collaborate more effectively by working on a shared trunk. Multiple team members can work on various features simultaneously without the need for prolonged feature branches
  3. Agile and iterative development — Trunk enables teams to deliver smaller, incremental changes to production. This iterative approach facilitates faster feedback from users and stakeholders, making adapting and incorporating changes based on their feedback easier
  4. Reduced code complexity — Long-lived feature branches can lead to significant code divergence and complexity. In contrast, trunk-based development keeps the codebase more maintainable by minimizing the time branches spend apart
  5. Faster time to market Trunk reduces the time between development and deployment, enabling faster delivery of new functionality to end-users. It supports continuous delivery and DevOps practices, helping organizations achieve shorter release cycles and respond swiftly to market demands
  6. Improved code quality and stability — Regularly integrating code changes into the mainline promotes early identification and resolution of issues. This practice also motivates developers to create simpler, self-contained code changes to test and validate

Overall trunk-based development offers benefits such as faster feedback, improved collaboration, reduced code complexity, agility, faster time to market, and support for continuous delivery and DevOps practices.

Trunk-based development key principles and practices

Trunk-based development adheres to several key principles and practices that guide its implementation. The following are important to keep in mind:

  1. Mainline as the single source of truth — The main branch, also known as the trunk or mainline, is the most reliable source of the codebase. This practice allows developers to regularly integrate changes into the mainline to maintain stability and stay current
  2. Frequent integration Following this principle, developers regularly integrate their code changes into the mainline throughout the day. This helps reduce the time spent on separate branches and allows for early detection and resolution of integration issues
  3. Small, self-contained changes This practice focuses on making small, self-contained changes to the code. This method breaks down the work into smaller pieces, which helps to reduce complexity, minimize conflicts, and enable faster integration and review processes
  4. Feature toggle — By using feature toggles, developers can separate the deployment of code from the release of new features, which allows for a gradual rollout of new functionality, A/B testing, and easy rollback if necessary
  5. Trunk stabilization — Periodic stabilization of the mainline is a common practice to maintain its releasable state. Teams allocate dedicated time to address integration issues, resolve conflicts, and fix any regressions or defects
  6. Continuous testing Automated tests, such as unit and integration tests, are regularly conducted as part of the continuous integration process. This approach lets the team quickly identify and resolve regressions, compatibility, and functional problems

These principles and practices help teams to deliver high-quality products, respond to changing requirements, and promote collaboration, agility, and faster feedback cycles.

Trunk-based development examples

Below are some examples of companies that have embraced trunk-based development:

Google

Google is known for its focus on speed and innovation in development practices. To support this, Google has integrated trunk-based development as a key component in its development approach.

With a vast codebase and numerous engineers, Google prioritizes integrating code changes into the main branch to ensure CI and swift feedback loops. This enables Google to provide product updates quickly while maintaining a scalable and reliable infrastructure.

Spotify

Spotify has also adopted trunk-based development. The teams at Spotify use brief-lived branches and frequently merge their modifications into the main system.

With this approach, Spotify can consistently introduce new features and enhancements to its platform, quickly respond to user feedback, and maintain high innovation.

Facebook

At Facebook, development teams make small, concentrated changes that they frequently integrate into the mainline. This technique enables them to continually enhance their platform, experiment with new features, and maintain excellent stability and performance.

Atlassian

Atlassian advocates for trunk-based development in its development practices. This approach allows teams to collaborate, integrate changes frequently, and swiftly deliver new features and bug fixes. Trunk-based development aligns with Atlassian’s agile and customer-centric approach to building products.

Challenges of trunk-based development

When adopting a trunk, teams may encounter certain challenges and need to consider several aspects. The most challenges and considerations come from:

Code conflicts

When multiple developers work on the same code areas, integrating their work can lead to conflicts. To avoid this, teams should establish clear communication channels and have effective strategies to resolve conflicts, such as conducting regular code reviews.

Test coverage and quality assurance

Teams need a thorough testing process covering unit, integration, and regression tests to validate code changes properly. To overcome this, investing in automated testing frameworks, creating quality assurance processes, and regularly monitoring the codebase quality is recommended.

Feature toggles management

Implementing feature toggles introduces additional complexity in managing different feature states and configurations. Teams need a robust toggles management system, ensuring proper configuration, monitoring, and control of feature flags.

Developer collaboration and communication

Team members must have strong collaboration and communication skills to have frequent integration. This includes effective communication, coordinating work, and staying informed on the mainline’s status. Teams can establish guidelines for code reviews, hold regular sync-ups, and use collaboration tools to facilitate effective communication and teamwork.

Learning curve and adaptation

Switching to trunk-based development can be a challenge for teams who are used to using long-lived feature branches or other development practices. Investing in training and supporting developers during the learning curve is important to make the transition smoother. This will help ensure the successful adoption of the trunk-based approach.

Risk management and rollbacks

When code changes are integrated and deployed faster, there is a risk of introducing bugs or regressions into the production environment. To prevent this, teams should implement strong strategies such as monitoring and alerting mechanisms and effective feature rollback processes.

The tools and resources required for implementation may vary depending on your team’s preferences, development stack, and organizational context. That said, that following are frequently utilized:

  • Git — Git is a version control system that provides branching and merging capabilities, allowing developers to easily work on short-lived branches and merge their changes into the mainline
  • JenkinsJenkins works as an open-source automation server that supports CI. It can be configured to monitor changes in the mainline repository and trigger automated build and test processes upon each integration, ensuring that changes are validated regularly
  • GitHub pull requests GitHub offers a code review tool and provides pull request functionality, allowing developers to review and discuss code changes before merging them into the mainline. This helps ensure code quality and collaboration within the development team
  • Application performance monitoring (APM) APM tools like New Relic, Datadog, or Dynatrace can provide valuable insights into the performance and behavior of code changes in production. They help monitor key metrics, identify issues, and gather feedback to drive continuous improvement
  • LaunchDarkly LaunchDarklyis a feature flag management platform that allows teams to easily manage and control the rollout of features in a trunk-based development environment. It provides features like gradual releases, A/B testing, targeting specific user segments, and rollback options
  • Confluence Confluence allows teams to document and share information about trunk-based development practices, workflows, and guidelines. It serves as a centralized knowledge repository for the development team.

Remember to evaluate the specific needs of your team and project and choose the tools and resources that best fit your requirements.

Conclusion

Trunk-based development promotes collaboration, agility, and faster delivery of high-quality software. By following this approach, you can iterate rapidly, respond to market needs, and maintain a codebase that is easier to manage and enhance over time. Trunk aligns well with modern software development practices, enabling teams to work together effectively.

Featured image source: IconScout

LogRocket generates product insights that lead to meaningful action

LogRocket identifies friction points in the user experience so you can make informed decisions about product and design changes that must happen to hit your goals.

With LogRocket, you can understand the scope of the issues affecting your product and prioritize the changes that need to be made. LogRocket simplifies workflows by allowing Engineering and Design teams to work from the same data as you, eliminating any confusion about what needs to be done.

Get your teams on the same page — try today.

Coastal Media Brand