Stackbook Logo
deploymentestablished · low operational burden

Trunk-Based Development

Also known as: tbd, mainline-development

Intent

Integrate small changes into a single shared branch at least daily, keeping it always releasable and hiding unfinished work behind flags.

Problem

Long-lived feature branches diverge, producing painful merges, late integration bugs and release freezes. Teams delay shipping because merging is risky, which makes each merge bigger and riskier.

Forces

  • •Integration cost grows with branch age
  • •Releases need a reliably green mainline
  • •Incomplete features must not reach users
  • •Review must stay fast to avoid blocking

Solution

Overview

Trunk-based development keeps all engineers working against one mainline. Branches, when used, last hours. The practice is a prerequisite for continuous delivery, and the DORA research links it to higher delivery performance.

How it works

Work is sliced into increments small enough to merge safely every day. Code merged but not ready is disabled by a flag or isolated behind an interface that still routes to the old implementation.

main: --o--o--o--o--o--o--o-->  (always green, deployable)
         \  /   \ /
          o      o      short-lived branches (under 1 day)

Pre-merge checks run unit tests and linting in minutes. Post-merge pipelines run slower suites and deploy. If main breaks, the rule is revert first and investigate second.

if flags.enabled("new-checkout", user):
    return new_checkout(cart)
return old_checkout(cart)

Pitfalls

  • A slow test suite that makes small merges painful, pushing people back to long branches.
  • Treating flags as permanent. Give each flag an owner and an expiry.
  • Merging half-baked code with no way to turn it off.
  • Big pull requests that wait days for review. Use pairing or small reviews.
  • No automatic revert policy for a red main.
  • Adopting it without trunk-quality safeguards such as required checks.

Key takeaways

  • Merge small, merge daily, keep main releasable.
  • Flags and branch by abstraction hide unfinished work.
  • Fast, trustworthy tests are the enabling investment.
  • Revert broken commits quickly.
  • Retire flags promptly.

✓ When to Use

  • •Teams practising continuous integration and frequent deploys
  • •Products with fast automated test suites
  • •Organisations wanting to remove long release stabilisation phases

✗ When Not to Use

  • •Weak test coverage that cannot guard main
  • •Open source projects with untrusted contributors needing gated review
  • •Multiple supported long-term release lines maintained in parallel

Pros

  • +Small merges, fewer conflicts
  • +Always-releasable mainline speeds delivery
  • +Faster feedback on integration issues

Cons

  • −Requires strong automated testing
  • −Needs flag discipline and cleanup
  • −Cultural change around small batches

Cost Profile

Infrastructure

Medium - fast CI capacity

Operational

Low - fewer branches and merges to manage

Cognitive

Medium - flags and incremental design thinking

Failure Modes

  • Broken main blocks the whole team

  • Dark features leak to users through misconfigured flags

  • Flag debt accumulates until behaviour is unpredictable

Real-World Examples

Alternatives

    Related Patterns

    • feature-flag
    • progressive-delivery
    • feature-flag-best-practices

    Competency Domains

    reliability opseconomics evolution