Blog
/

Trunk-Based Development: How Feature Flags Enable True Continuous Integration

Flagpool Team
··
Tree with a broken branch and fresh growth on its trunk, illustrating the shift from long-lived branches to trunk-based development.
  In this article

It is Friday afternoon. The feature branch has been open for three weeks, main has moved on, and the pull request is now large enough to have its own weather system. Nobody planned for the merge to become the week’s main event. It just happened one “almost done” day at a time.

Trunk-based development is one way teams avoid that pile-up: integrate small changes into a shared trunk frequently, rather than letting changes drift apart on long-lived branches. Feature flags can help when the code is ready to integrate before the feature is ready for users—but they are one tool in the approach, not a magic shield or a reason to skip review.

What trunk-based development actually means

The trunk is the team’s shared integration branch, often called main. Developers keep changes small and bring them into that shared line frequently. Some teams commit directly; many use short-lived branches and pull requests. The important distinction is not “branches or no branches.” It is whether changes stay isolated long enough to make integration a risky event.

For a closer look at code isolation versus runtime release control, see feature flags vs. feature branches.

Short feedback loops make it easier to spot conflicts and integration problems while the change is still fresh. They also encourage smaller reviews, which are generally easier to understand than a month of work submitted all at once.

A tree with a gate beside a broken branch and new growth, illustrating feature gating for trunk-based development.

Trunk-based development is not the same as deploying every commit straight to production. Integration, deployment, and release are related but separate decisions. A team can integrate changes frequently, verify them in CI, deploy when its delivery process allows, and still decide separately when users should see a feature. See deploy vs. release for more on that distinction.

Where feature flags fit

Suppose (hypothetical example) a team is rebuilding its billing page. The new page is not ready for customers, but the team wants to build it in small pieces and integrate those pieces as they go.

A feature flag can preserve the current page as the default while the new path is being built:

if (flags.newBillingPage) {
  return renderNewBillingPage()
}
return renderCurrentBillingPage()

The team can merge a small change behind the flag, test the existing path, and continue without requiring the entire billing project to land as one giant diff. When the new page is complete, it can be enabled for an internal audience or beta testers and released more broadly when ready.

This is a useful separation: the team can integrate code before choosing to expose it. But flags do not make incomplete code automatically safe. The default path must remain correct, both paths need appropriate tests, and the flag should control a coherent feature rather than scattering unrelated conditions throughout the application.

For implementation details, see the Flagpool trunk-based development guide and feature flag concepts.

Why integrate in smaller steps?

The main payoff is not an absence of merge conflicts—conflicts still happen. It is avoiding weeks of divergence that make conflicts and integration defects harder to resolve.

  • Problems surface earlier. A mismatch between a new component and a changed API is found while both changes are still easy to discuss.
  • Reviews stay focused. A reviewer can reason about one small, cohesive change more easily than a sprawling feature branch.
  • Work is easier to pause or redirect. If product priorities change, the team has less unmerged work entangled with unrelated improvements.
  • Release timing becomes more flexible. A feature can be integrated and deployed before its audience is ready to receive it, provided the code is safe to have present.

There is a people benefit too: developers spend less time rebasing a private universe onto main and more time getting useful feedback on work that is still understandable.

None of this removes the need for a healthy CI pipeline. Trunk is only as reliable as the checks, review practices, and deployment safeguards around it. Frequent integration without automated tests can simply help you discover breakage more frequently.

Building a feature that takes weeks

“Small changes” does not mean “small projects.” A feature may take a month to complete; the goal is to avoid keeping every part of that work isolated for the whole month.

For the hypothetical billing-page project, the team might:

  1. Extract a shared billing-page interface while the current page remains in use.
  2. Add the new page in small, reviewable pieces behind one clear release boundary.
  3. Test the enabled and disabled paths in CI, including relevant data and navigation behavior.
  4. Enable the new experience for internal users, then a suitable beta audience.
  5. Expand access after checking support feedback and technical health.
  6. Remove the old path and temporary flag once the migration is complete and safe.

Another useful technique is branch by abstraction: introduce a stable interface around an existing implementation, then replace the implementation in steps. It is especially helpful when changing a shared or high-risk part of a system. The key idea is to make each integration step coherent and compatible—not to hide a large unfinished rewrite behind one switch.

What a feature flag does not solve

A disabled feature can still have effects if its code runs before the flag check, changes a shared data format, triggers background work, or alters behavior outside the gated path. Database migrations, API contracts, and events consumed by other services need their own compatibility plan. A flag can choose between application paths; it cannot undo a destructive migration or make old and new services understand different schemas.

Keep the current behavior working while the new path is incomplete. Test both sides of the flag, give the flag a clear owner, and plan when to remove it. A temporary flag left behind for years becomes another piece of branching complexity. The feature-flag hygiene guide has more on managing that lifecycle.

And trunk-based development does not mean every team has to merge directly to main or deploy multiple times a day. Short-lived review branches can be a good fit; so can a slower release cadence for products with careful operational or regulatory requirements. Optimize for frequent, low-risk integration—not a calendar target chosen because it sounds impressive.

How to try it without a process revolution

Choose a modest feature that can be divided into independently reviewable steps. Agree on a few practical habits:

  • Keep changes small enough that a reviewer can understand their purpose.
  • Integrate frequently through the team’s normal review process.
  • Run meaningful automated checks before merging.
  • Use a flag only when code needs to be present before it should be visible.
  • Make sure the disabled path remains safe, and test both experiences.
  • Assign an owner and cleanup point to temporary flags.

After a few changes, inspect what actually improved. Are changes easier to review? Are integration problems found sooner? Is work still accumulating behind a long-lived branch, just under a different name? Use those answers to adapt the workflow.

Trunk-based development is not a contest to eliminate branches or maximize commits per day. It is a way to keep integration routine instead of dramatic. Start with one small change, get it into the shared trunk safely, and build the habit from there.