Reliability and security · L1CI/CD and trunk-based development

CI/CD and trunk-based development

Merge small changes every day, let a machine build and test each one, and ship the same tested build to production.

L1 Must-knowReliability and security18 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 22 Oct 2026 · How we check content
Section 1 of 8

What broke

On 1 August 2012, Knight Capital's trading system sent millions of orders it should not have sent. In about 45 minutes it got over 4 million executions (filled trades) in 154 stocks. Knight lost over $460 million. 1

The cause was a deploy. Starting on 27 July, Knight put new code on its eight order-routing servers, a few at a time. A technician did not copy the new code to one of the eight. No second technician reviewed the deploy, and no written procedure asked for one. 1

The new code reused an old flag. On seven servers the flag turned on the new feature. On the eighth, it woke up old code called Power Peg, unused since 2003. A 2005 change had broken how that code counted filled shares. So it never knew an order was filled, and kept sending more. 1

It got worse. While trying to fix it, the team removed the new code from the seven good servers. Now those servers ran the old code too. 1

The SEC report is about missing controls, not about CI tools. But the pattern is common. A manual, step-by-step deploy means each server can end up different. In our view, an automated pipeline that ships one build to every server, and checks the version, makes this mistake much harder.

Section 2 of 8

The idea in simple words

Three ideas work together.

Continuous integration (CI). Everyone merges small changes into one shared branch, often. Fowler suggests every developer commits to the mainline every day. 2 Each merge is built and tested by a machine. If the build breaks, you fix it right away. 2

Continuous delivery. Your software can be released to production at any time. Deploying any version is one button press. 3

Continuous deployment. One step further. Every change that passes the pipeline goes to production with no human step. With continuous delivery you are able to deploy often, but you may choose not to. 3

Trunk-based development is a branching model and "a key enabler of Continuous Integration". Developers work on one branch, called trunk or main, and avoid long-lived branches. 5

The key idea. Small changes, merged often, each one built and tested by a machine. Small changes are easy to review, easy to test and easy to undo.

Section 3 of 8

How it works

Step through one commit, from trunk to users. Use Next and Back, or the ← and → keys.

One commit on trunk: built once, tested, promoted, then turned on with a flagmain (trunk) Build Test Package Staging Production Feature flag PR merged · 60 linescommit a1b2c compile oncefrom commit a1b2c unit + integrationall green · 8 min image app:a1b2cstored and signed same image a1b2csmoke tests pass same image a1b2cflag off · users see no change ✓ on for 1% of userswatch errors, then widen SeniorPath
  1. A developer merges a small pull request into main. It changes 60 lines. The new feature is inside a feature flag that is off.
  2. The pipeline starts on its own. It builds the code once, from this exact commit.
  3. Unit and integration tests run. They finish in 8 minutes, so the developer still remembers the change if something fails.
  4. The pipeline packages the build into one image, app:a1b2c. It stores the image and signs it. Nobody builds it again.
  5. The same image goes to staging. Smoke tests check that it starts and answers requests.
  6. The same image goes to production, in stages. The flag is still off, so users see no change. Deploying code is not the same as releasing a feature.
  7. The team turns the flag on for 1% of users and watches errors and latency. If they rise, they turn the flag off in seconds. If not, they go wider.
Step 1 of 7

Why big merges hurt

When a branch lives for weeks, everyone else keeps changing trunk too. At the end, you face a long merge with many conflicts. Fowler calls the worst case "integration hell": every integration bug you fix shows two more. 2

Short-lived feature branches avoid this. A branch should live a couple of days at most, with one developer, or two when pairing. You open a pull request, CI runs, a teammate reviews, you merge and delete the branch. 6

For work that takes weeks, merge it in small parts behind a feature flag that is off. 5 Users see nothing until you turn it on. Deploying code and releasing a feature become two separate decisions. 4

The pipeline

A deployment pipeline starts on every change. The first stage, the commit stage, should take only a few minutes. Each passing stage starts the next one. 4 A common shape is:

  1. Build. Compile the code and resolve dependencies.
  2. Test. Run unit tests, then slower integration tests.
  3. Package. Make one build artifact, such as a container image.
  4. Deploy. Send that artifact to staging, then to production in stages.

Build once, then promote. "Only build packages once" is one of the core pipeline practices. You want to be sure the thing you deploy is the thing you tested. 4 Deploy it the same way to every environment. 4 Knight's servers ran different code. With one artifact, promoted everywhere, that is much less likely.

Keep main green

A red build on trunk blocks everyone. If the commit stage fails, fix it at once, and nobody adds new work on top. 4 Often the fastest fix is to revert your change, then fix it calmly on a branch.

GitHub can enforce part of this. With required status checks, nobody can merge into a protected branch until the checks pass. 10

Keep feedback fast

Google's CI chapter says the cost of a bug grows almost exponentially the later you catch it. So CI aims for fast feedback. 7 Google runs only fast, reliable tests before submit. Slower tests run after submit. 7 Fowler says a ten-minute build is reasonable. 2

Flaky tests hurt CI badly. They erode trust in the build, similar to a broken test. They also make it harder to find which change to roll back. 7 See Testing strategy for how to keep a suite fast and trusted.

Measure delivery: the DORA metrics

DORA studies software delivery. Its guide now names five metrics, in two groups. 8

Throughput:

  • Change lead time: time from a commit in version control to that change running in production.
  • Deployment frequency: how many deploys you do in a period, or the time between them.
  • Failed deployment recovery time: how long it takes to recover from a deploy that fails and needs immediate action.

Instability:

  • Change fail rate: the share of deploys that need immediate action after they go out.
  • Deployment rework rate: the share of deploys that are unplanned and happen because of an incident in production.

Note that recovery time counts as throughput here, not instability. 8 DORA says speed and stability are not trade-offs. For most teams the metrics are correlated. 8

Protect the pipeline itself

Your pipeline can run code from strangers, so it is also an attack path. GitHub advises pinning third-party actions to a full-length commit SHA. A tag can be moved or deleted by someone who gets access to that repository. 11 Our advice: pin your dependencies with a lockfile, scan them for known flaws, and sign what you build. SLSA is a checklist of controls that help stop tampering with builds and packages. 12 See Dependency and supply-chain security and the OWASP lesson.

Section 4 of 8

Trade-offs

OptionMerge painNeeds strong automated tests?Fits
Trunk-based, short branchesYes , low. Small daily merges.Yes CI is the safety net.Most teams that deploy a web service often.
Long-lived feature branches (GitFlow style)No , high. Weeks of drift, then a big merge.Less, but bugs show up late.Software with several versions in use at once, like installed apps.
Continuous deliveryNot about merging.Yes Every build must be releasable.Teams that want a human to choose the release time.
Continuous deploymentNot about merging.Yes , plus good monitoring and fast rollback.Teams with trusted tests, staged rollouts and feature flags.

The author of GitFlow wrote in 2020 that web apps are usually delivered continuously. For them he suggests a simpler flow. GitFlow still fits when you must support several versions in use at once. 9

Simple rule: start with trunk-based development and continuous delivery. Move to continuous deployment once your tests and rollback are trusted.

Section 5 of 8

At work: how a senior uses this

  • Keep pull requests small. If a PR is open for more than two days, ask how to split it.
  • Ask "can we ship this unfinished, behind a flag?" before anyone creates a long-lived branch.
  • Treat a red main branch as an urgent problem for the whole team. Revert first, debug second.
  • Watch the CI time. When it grows past about ten minutes, move slow tests out of the merge check or run them in parallel.
  • Quarantine flaky tests with an owner and a date. Never make "just re-run it" the normal fix.
  • Check that production runs the exact artifact that passed tests. Ask: "Can anyone deploy a build that did not go through the pipeline?"
  • Track change lead time and change fail rate together. Use them to find slow or risky steps, not to rank people.
  • Remove dead code and old flags. Knight's old code stayed callable for years. 1
Section 6 of 8

With AI

AI coding agents now open pull requests on their own. On GitHub, Copilot's cloud agent can push to only one branch. By default, CI does not run on its pull request until a person with write access approves the workflow run. The person who asked the agent cannot approve its pull request. 13 In our view, CI becomes the main safety net for agent code. It runs on every change and does not get tired.

What to ask the agent

"Here is our CI workflow. Find steps that are slow or run in series but could run in parallel. Estimate the time saved for each."

"List every third-party action and dependency in this repo that is not pinned to an exact version or commit SHA. Propose the pinned versions."

"This feature is too big for one PR. Split the plan into PRs of under 200 lines. Each must keep main green, with new behaviour behind a flag that is off."

What to check yourself

  • The agent's tests test real behaviour. A test with no real assertion is always green.
  • The pull request does not change the CI workflow, skip tests or loosen checks without a clear reason.
  • New dependencies are real, well-known packages at pinned versions.
  • The agent did not "fix" a red build by deleting or disabling a failing test.
  • A human reviewed the diff before merging, even when every check is green.
Section 7 of 8

Check yourself

1. Your team's pipeline tests every merge and puts each passing build into production with no human step. What is this called?

Show answer

Continuous deployment. In continuous deployment every change that passes the pipeline goes to production on its own. Continuous delivery means you could deploy at any time, but a person chooses when.

2. A feature will take three weeks. How do you keep working on trunk?

Show answer

Merge small parts every day, with the unfinished feature behind a flag that is off. Small daily merges keep conflicts small. The flag keeps unfinished work hidden from users.

3. Why should the pipeline build the artifact once and promote it, instead of building again for production?

Show answer

So the thing you deploy is exactly the thing you tested. A new build can pick up different dependencies or settings. Promoting one build means your tests are about the real release.

4. Which pair are both DORA throughput metrics?

Show answer

Change lead time and deployment frequency. DORA groups change lead time, deployment frequency and failed deployment recovery time as throughput. Change fail rate and rework rate measure instability.

5. An AI agent opens a pull request. Its tests all pass. What is still your job?

Show answer

Read the diff, check that the tests test the right thing, and look for changes to the pipeline itself. CI only checks what its tests check. An agent can write weak tests or change the workflow files, so a human still reviews.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 13 sources and related lessons
  1. U.S. Securities and Exchange Commission, Order against Knight Capital Americas LLC, Release No. 34-70694, 16 October 2013 (opens in a new tab)
    The official findings on the August 2012 deploy that missed one of eight servers, and what it cost.
  2. Martin Fowler, “Continuous Integration”, martinfowler.com (revised 2024) (opens in a new tab)
    The classic description of CI, the ten-minute build, fixing broken builds at once, and why long branches hurt.
  3. Martin Fowler, “ContinuousDelivery”, martinfowler.com bliki (opens in a new tab)
    A short, exact explanation of continuous delivery and how it differs from continuous deployment.
  4. Jez Humble, “Patterns”, continuousdelivery.com (opens in a new tab)
    The deployment pipeline, the commit stage, and the rule to build packages only once.
  5. Paul Hammant and contributors, trunkbaseddevelopment.com (opens in a new tab)
    What trunk-based development is, and the techniques that let a team avoid long-lived branches.
  6. trunkbaseddevelopment.com, “Short-Lived Feature Branches” (opens in a new tab)
    How long a branch should live, and how many people should work on it.
  7. Rachel Tannenbaum, “Continuous Integration”, chapter 23 of Software Engineering at Google (O'Reilly, 2020) (opens in a new tab)
    Fast feedback, presubmit and post-submit tests, green head, and how flaky tests hurt CI at Google scale.
  8. DORA, “DORA's software delivery performance metrics”, dora.dev (opens in a new tab)
    The current names and definitions of the delivery metrics, grouped into throughput and instability.
  9. Vincent Driessen, “A successful Git branching model”, nvie.com (with a note of reflection, 2020) (opens in a new tab)
    The author of GitFlow explains when it still fits and when a simpler flow is better.
  10. GitHub Docs, “About protected branches” (opens in a new tab)
    How required status checks block a merge until CI passes.
  11. GitHub Docs, “Security hardening for GitHub Actions” (opens in a new tab)
    Why you pin third-party actions to a full commit SHA, and how to scan workflows.
  12. OpenSSF, SLSA (Supply-chain Levels for Software Artifacts), slsa.dev (opens in a new tab)
    A checklist of controls that stop people tampering with your builds and packages.
  13. GitHub Docs, “Risks and mitigations for GitHub Copilot cloud agent” (opens in a new tab)
    How an AI agent's pull requests are limited, and why its CI runs only after a human approves.

Real incident: Knight Capital, 1 Aug 2012: Knight Capital: a missed server lost over $460 million in 45 minutes

Related: Testing strategy that scales · Flaky tests and test reliability (coming soon) · Safe deploys and config changes · Feature flags and entitlements · DORA metrics and delivery performance (coming soon) · Dependency and supply-chain security · Reviewing code written by humans and AI · Working with coding agents

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper