Overcoming Barriers to Trunk-Based Development

This chapter discusses what Trunk-Based Development is, why it’s a good approach for team software development, what some common barriers are, and why a Patterns approach can guide you past the barriers.

Why Code Lines Matter

When you work on a software project, you are almost certainly using a version control system (VCS), such as Git. Software Configuration Management (SCM) — in particular, Version Management and Branching— is essential to the software development process. Providers such as GitHub and GitLab make it easy to incorporate version management into your development flow, and the VCS is part of every aspect of development, from coding to release.

As a developer you likely don’t give as much thought to your interactions with a VCS as you do to how you test, interact with a coding agent, or use debugging tools, etc. But the VCS — and the Code Line model a team uses defines the workflow from planning to release, and as such is central to how team members work and collaborate with each other.

What’s a Code Line

In its simplest form, a single code line where each developer commits changes and which is used as a source of code to deliver, a VCS gives you the ability to do two things that few would dispute as valuable, in spite of the (small amount of) overhead:

As the team expands to two or more people, you need to coordinate and collaborate so that multiple developers can contribute to the same codebase. The right code-line model can make you more efficient and agile—enabling you to integrate code from multiple team members quickly and without error. The wrong code-line model — or the right one used incorrectly — can slow you down, make it harder to introduce functionality, and, in general, make writing code unpleasant.

While design, testing discipline, and tooling to support Continuous Integration get a lot of discussion—as they should—team software development is collaborative, and the choice of code-line process affects the effectiveness of the best technical and planning process.

While developers often don’t think much about version control in their day-to-day work compared to other development process concepts such as testing and planning, the code-line model defines your workflow.

A Good Code Line Model

A good code line model lets you integrate quickly enough while keeping the error rate tolerable. (What “quickly” and “tolerable” mean will vary by team). “Good” doesn’t mean friction-free; a small amount of friction can help reduce the chance of introducing errors into a code line. You want to reduce overhead, increase collaboration, and deliver value more quickly. The right code-line model also lets you focus on the fun and interesting part of software development: writing and delivering code that adds value.

In many cases, the “right” code-line process for team software development is one based onTrunk-Based Development principles. Approaches like Git Flow, which introduce delays— while frequently used- are not right for team development, being more suited for environments where the contributors to a code base aren’t members of the same organization. Other models like GitHub Flow or other feature-branch-oriented approaches are better, but they still introduce avoidable delays and associated risks.

A Trunk-Based Development approach — where changes get integrated into a Main Line quickly — is a good solution for many product development organizations, but change is more involved than simply saying “let’s have fewer (or no) branches;” there are technical, planning, and cultural hurdles to overcome. My goal is to guide you through these challenges using a Pattern Language.

The Developer Experience

Developing software involves the following steps: - Deciding what to work on. This is usually related to a business goal and can come from a conversation, a User Story, a ticketing system, or whatever mechanism your team uses to identify work. - Deciding how to do the work. Identify units of work that can be integrated independently so that you make incremental progress. - Building. Write the code that implements the implementation steps you planned. - Getting feedback on the work before integrating. This can include tests, peer review or feedback, or other forms of quality checks. - Integrating the work successfully. Verify that your change didn’t break the main code line for anyone else, either from a technical sense (an error in the code) or a business sense (exposing a feature prematurely). It also means avoiding mechanical errors that make integration difficult, such as merge conflicts and tests that pass before integration but fail afterward. - Delivering the work. This means releasing the application and making the value available to users.

Deciding what to work on usually depends on forces outside the development team, such as business goals, though the team can certainly be involved in the process. The rest is ideally in the scope of the software development organization. One of the more reliable ways to achieve these goals is to integrate code early and often into a common Main Line: - Frequent integration makes code conflicts less likely. - Smaller changes are also likely to be lower risk. - Smaller changes also make frequent integration more likely because of the time it takes to implement them.

While the mechanics of doing these things sounds easy, it may take some changes to do successfully:

Some of these issues are easy to adjust for, with technical or training solutions. We can speed up a CI pipeline with parallelization or larger CI servers.

The harder problem is how many organizations approach risk. Rather than acknowledging the chance that errors will occur, they assume that adding more—rather than fewer—gates will create more stability. This sounds reassuring but is often problematic.

The Illusion of Control: Speed and Safety

Frequent integration and fewer code lines have advantages. Why doesn’t everyone do it? And why are Git Flow, long-lived feature branches, and concurrent, long-lived release lines still common?

The reasons often come down to a combination of: - Perception, Assumptions, and Habit: We do things in familiar ways because they work well enough, change is hard, and we don’t see the cost of not changing - Infrastructure, environment, and discipline: Successful trunk-based development requires specific elements in your way of working. Once you realize the benefits of working differently, you can start taking steps to improve your workflow. Let’s explore some of the barriers

Habits and Illusions

When teams decide how to set up their code lines, they typically are concerned with releasing software that doesn’t break anything. Teams have traditionally managed integration by adding gates to the process to provide quality checks, for example, using Pull Requests, and using a model such asGitFlow that has intermediate integration/stabilization branches. While these gates and checks appear to ensure quality (and sometimes they do find errors!), they also slow the rate of integration and potentially slow the larger development process.

The approach of moving slowly to ensure quality is based on the idea that there is a tradeoff between stability and speed, and that slow is safe because when you control change you can verify the impact of every change. This is anillusion of controlandresearchsays that there need not be a tradeoff:

DORA’s research has repeatedly demonstrated that speed and stability are not tradeoffs. In fact, we see that the metrics are correlated for most teams. Top performers do well across all five metrics, and low performers do poorly.

Rather than making the integration process safer, moving slowly can end up introducing more risks, including: - merge conflicts and more complicated merges in general

This doesn’t even consider the impact on the developers: - time spent waiting for feedback leads to people losing context and a tendency to multitask

Speed and Feedback

Another argument for maintaining staged branching models with slow review processes is “compliance.” While many of the slower approaches to development support compliance requirements, and are also what auditors are used to seeing, you can often meet the requirements with different approaches.

One reason these models persist is that they have worked in the past, and people don’t think about how the context has changed. The computing consultant Jerry Weinberg used the term _survival rules_to describe this idea in his book Becoming a Technical Leader:

Survival rules are not stupid; they are simply over-generalizations of rules we once needed for survival. We don’t want to simply throw them away. Survival rules can be transformed into less powerful forms, so that we can still use their wisdom without becoming incongruent

Consider: at one point, a code freezewas a common practice; new code wasn’t integrated into code lines until a release candidate was verified. Robust branching makes code freezes obsolete. Similarly, in the context of agile software development and practices such as Continuous Integration, Test-Driven Development, and small, frequent commits, a safety model based on slowing down integration doesn’t serve the purpose it did in other contexts. But you may still find you don’t have the mechanisms to do trunk-based development well. But you can fix that.

Technical and Planning Processes

Once you decide that Trunk-Based Development might be a good idea, you may still have a hard time succeeding. The following are common issues: - Slow Reviews: Having a review isn’t a bad thing per se, but waiting for a review is wasted time. You need to minimize the time spent waiting for feedback, and work to get good-quality feedback. - Integration Errors: One premise of trunk-based development is that code gets integrated quickly without breaking the code line (frequently — mistakes happen). You need a good approach to automated testing to catch errors as early as possible. - Incomplete Features: You should be able to integrate code in a way that doesn’t change production code before a feature is ready. There are technical and design mechanisms for this. You also need to make sure that norms allow for integrating work that doesn’t result in a complete feature. - Difficulty fixing errors quickly. Even with the best technical discipline, errors will happen. You need a process that allows for rapid recovery from errors, either by rollback, fix forward, or (short-lived) release branches.

The Path to Trunk-Based Development

With the right mechanisms in place a code line model that facilitates quick and safe collaboration without slowing you down can be the key to fast, safe, delivery. The Patterns in this book will be a guide to helping you understand not just the practices that mechanically allow for Trunk-Based Development, but the supporting ecosystem that enables you to move your team toward this approach.

Change is hard, but you can still use practices such as Pull Requests (provided they are quick), mechanisms such as work branches (provided they are short-lived), and delivery approaches such as release lines (provided that you only have one at a time).

The Main Line Code Line patterns are one way that illustrates the dependencies for Trunk-based development. #

The Role of AI

How you use code lines and work streams matters as much, if not more, when coding with AI than when working solely with a team of human developers. AI can speed up certain parts of the coding and feedback process, letting humans in the loop add more value faster. But core code-line patterns still hold whether you use AI as an assistant or as an agent writing and committing code autonomously. If anything, more work being done by developers working with agents, or by agents working somewhat autonomously, means you need to be more thoughtful about how best to manage the additional, and perhaps larger, parallel work streams.

AI can change how we implement certain practices throughout the lifecycle. On the coding side of the delivery pipeline, AI assistants can help a developer — or team — be more productive, but productivity isn’t simply measured by output; it’s measured by the functionality delivered by code that’s maintainable and integrated into the main line. You still need to consider how code review fits in, and what checks you need before you integrate changes to the Main Line. Using AI to write code could lead to larger integration units, which affects how you review and test the code and how often you integrate.

AI Tooling can support the review process by focusing and reducing — or in some cases eliminating — the need for peer review, allowing a human reviewer to focus on the parts where they can add more value, whether the code in question was authored by an agent or a human.

As Adam Brotman and Andy Sack say in their book Agents, Inc, AI makes the judgment and experience builders (including developers) bring to the work even more important than before:

That is what builders now bring: problem insight, direction, judgment, and governance. The code still matters. The architecture still matters. Security still matters. However, the bottleneck has changed. For twenty years, companies had more ideas than engineering capacity. In the agentic era, they will have more building capacity than judgment.

It’s not just about delivering more code: it’s about delivering maintainable value more quickly. This means reviewing the work agents do, whether that’s done by the developer guiding the agent, by another team member, by automated checks (or other agents), or by any combination of these.

To use AI successfully in your development process, you need a code-line process—including a branching model and supporting mechanisms —that lets you move quickly and safely. A Main-line-based model such as Trunk-Based Development can be that process, as long as you consider how you’ll ensure speed and safety. The SCM Pattern Language, with minor implementation updates, can help.

The Context

You are working on a software project that has multiple contributors. The contributors can be team members, agents, or a combination. You want a mechanism that enables various contributors to collaborate and makes it easy for the various work streams to integrate.

Essential Trunk Based Development

Trunk-based development , which supports rapid integration, has two key elements:

While there seems to be a simple approach to this: “Just Don’t Branch!”, frequent integration into the Main Line reliably is difficult. To integrate code into the main line quickly and safely requires thinking about technical, planning, and organizational environments:

If you currently have a code-line process with long-lived feature branches (because you want to integrate complete features), long-lived release branches (because you need to provide patches in the case of errors, because you release infrequently), etc., dramatically reducing the number of code lines can feel daunting. But you want to do it faster in a way that is both effective and gives stakeholders the confidence to try a new approach. The good news is that you can move towards trunk-based development incrementally. Some of the steps are simple process changes, but others require rethinking how you work: - Organize your work into atomic — preferably smaller— units that can be integrated more quickly into the Main Line using work branches rather than feature branches. - Release from the Main Line, creating a Release Line in the event that you need to provide a fix before the next release. - Reduce the time it takes to create a stable release, so that Release Lines can be short-lived.

These workflow changes aren’t necessarily trivial. They may involve organizational and cultural changes in addition to technical ones. You can still leverage the CI and Pull Request flow you use now, with some modifications to integrate smaller, atomic units of work quickly. By reducing the time it takes to integrate changes, you can get the benefits of Trunk-Based Development.