By Robbert van Os
Posted on 2023-04-19T00:00:00.000Z

Boost Software Delivery Speed & Quality with Trunk-Based Development

Discover how trunk-based development accelerates software delivery and improves quality. Compare it to other branching strategies and learn implementation tips.

Rapidly growing software companies need to deliver high-quality, fast solutions to maintain their edge. Trunk-based development, backed by Agile and DevOps, enables efficient, quick code updates and consistent delivery, outperforming alternative branching strategies in software development.

Trunk-based development?

Trunk-based development simplifies code versioning by maintaining a single "trunk" as the code repository's source of truth. This approach reduces merging issues and complexity, saving time compared to working with multiple local branches.

Trunk-based development requires:

  • Single source of truth in the "trunk" branch with the latest production-deployable code.
  • Short-lived branches contributed to the central source of truth and worked on the latest version to reduce merge risks and flaws.
  • Small and frequent commits combining all code changes, even unfinished features, to guarantee seamless integration with the rest of the codebase.
  • Communication across development teams when they touch comparable modules and modify code faster.
  • Continuous integration and delivery for rapid deployment cycles since the team works together.
  • Automated testing for fast code feedback while iterating through frequent contributions and production deployments.
  • Feature flags to enable or deactivate features without stopping iteration.

Trunk-based development reduces waste and production line faults by restricting work-in-progress, a Lean Principle. Its use in software means that modest code changes are often integrated into the main line and released after passing quality tests.

This paradigm encourages developers to commit their code frequently and resolve problems early. Trunk-based development reduces merge conflicts, increases code quality, and speeds up product delivery by limiting branches to the newest code version.

Trunk-based development vs other methods

While Gitflow, GitHub Flow, and Feature Branch offer organized team cooperation, they involve complex merging, slow testing, and version management. Trunk-based development, with just-in-time integration and single-branch updates, optimizes the software pipeline and prevents hidden delivery restrictions.

The main differences of trunk-based development are:

  • Other branching models use numerous long-lived branches, such as development, feature, and release branches with various lifecycles.
  • Branching and merging: some branching models utilize long-lived branches merged back at certain times and with sophisticated rebase scenarios, while others use several short-lived branches swiftly merged back into the trunk.
  • Collaboration and code sharing: developers are encouraged to commit code changes numerous times each day and settle disputes early, making it easier for teams to interact. Other techniques support longer periods without merges.
  • Code quality and delivery: reduces merge conflicts and accelerates minor software increment delivery, while alternatives lead to more complex merging procedures, more code conflicts, and slower delivery.

The choice of branching model depends on the team's needs, organizational environment, and alignment. Trunk-based development, used by Google, Spotify, Etsy, and Netflix, may not suit all teams. Experienced developers benefit more from this approach, while new engineers may face challenges.

Using Trunk-Based Development

Trunk-based development requires various software approaches and a gradual deployment, as developers and teams need time to adapt. Syncing the software's technical and organizational mechanisms is essential. To maximize the benefits of mature trunk-based development, follow these four stages:

1. Ad-hoc/Initial Maturity

Introduce the team to the benefits of trunk-based development, and encourage frequent coding and reviewing.

Driving actions:

  • Teach the team about trunk-based development's advantages.
  • Encourage small codebase modifications and avoid big, monolithic changes.
  • Set up a synchronous code review process.

2. Recurring Maturity

Establish software automation and environments for frequent iterations.

Steps:

  • Implement CI/CD tools for automating code-related tasks.
  • Create a staging environment and develop test automation architecture.
  • Use feature flags for new features to enable/disable as needed.

3. Managed Maturity

Create a more resilient and scalable trunk-based development method with a clear release process.

Factors:

  • Set up a release train with testing, staging, and production environments.
  • Create a rollback plan.
  • Monitor code quality, build and deploy timeframes, and rollback success rates.

4. Scalable Maturity

Divide the process into roles as the codebase grows and support ongoing change with mature techniques.

Key practices:

  • Establish a platform team responsible for managing the CI/CD pipeline.
  • Use advanced testing approaches, like chaos engineering and continuous monitoring.
  • Continuously refine the process using data and team feedback.

Which technologies support trunk-based development?

Trunk-based development uses versioning, automated build, deployment, and testing like other branching systems. Trunk-based development tooling requires additional capabilities to facilitate rapid iteration.

Supportive tooling aids the progressive maturity and scalability of trunk-based development. As developers commit more frequently to the same codebase, builds, tests, and deployments increase. If the integrated tooling takes too long, code changes accumulate, raising work-in-progress and potential issues. Proper attention to specific aspects of the system is crucial to avoid limiting factors.

The trunk-based development pipeline's main bottlenecks are:

  • Merge requests rate to give rapid notification, alarms, and automated delegation to avoid pending merge requests accumulating and requiring costly developer rework.
  • Build time execution with fast compilation and package building to quickly have artifacts ready for deployment. Intelligent impact analysis tools help optimize unit tests.
  • Automated test execution may become the biggest bottleneck of all once execution times change from seconds to hours. Run essential tests first with parallel testing and tooling, then execution tests with less constraints.

This comprehensive tooling will lay the groundwork for scaling trunk-based development across your organization. As we've seen, experience matters, and best practices and recommendations can expedite trunk-based development in an organized approach.

Tackling trunk-based development?

Trunk-based development affects all developers' workflow and software quality and speed. Preparation and organizational change can overcome common problems.

The following issues will be faced while shifting to a trunk-based development pipeline:

  • Adoption: changing our personal behaviors takes time, and this is so for transforming an organization. Start slowly and focus on early adopters to demonstrate the value of behaviors like frequent committing and local testing.
  • Communication: team members must work together more on the same codebase. Structured communication and protocols help maturity.
  • Merge conflicts: trunk-based developers must quickly resolve code conflicts to prevent going backwards. Maintain code ownership, work distribution, and synchronous code reviews.
  • Feature management: many modifications in a shared codebase that is continuously going forward require mechanisms to disable troublesome sections of code. The team must practice feature flag implementation and removal.
  • Code quality: frequent code changes make structural refactoring harder. Organizations have to set explicit code ownership, refactor in tiny steps, and rely on automated tests, intelligent refactoring, and code review.
  • Technical debt: iteration with many feature flags and higher code quality will increase technical debt faster. The team must manage technical debt as part of its regular activity, using the pipeline with controlled limiting variables to improve quality quickly.

These issues are ongoing with trunk-based development and must be handled by leading by example, sharing the vision and anticipated challenges, and establishing a plan to gradually execute organizational changes. As we've seen, trunk-based development is more than simply coding—it's a mindset.

Conclusion

Trunk-based development enables fast, high-quality software delivery, allowing businesses to adapt quickly and meet goals. Before implementing, assess organizational maturity and culture, as it may not suit fully dispersed teams with many juniors. This approach requires mastering end-to-end pipeline integration, organizational alignment, and scalable tooling. It marks a shift from Software Engineering to Quality Engineering, with trunk-based development as the foundation for improved and expedited software delivery.