Continuous integration as a practice
CI is a team habit, not a server: merge small changes into the mainline at least daily, verify each one automatically, and fix a broken build first.
Flow, feedback and continuous learningTeam topologies and you build it, you run it
Continuous integration as a practice
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Continuous integration means everyone merges their work into a shared mainline at least once a day, and every merge is verified by an automated build and tests.
- The longer two lines of work stay apart, the more they diverge, and the harder and riskier the eventual merge becomes.
- A CI server running tests on long-lived feature branches is automation, but it is not continuous integration, because the work is not being integrated.
- The team rule that makes CI work is that a broken mainline is fixed or reverted within minutes, before anyone merges anything else.
- Unfinished features can still be integrated daily by hiding them behind a feature flag or by building them in small steps that do not change behaviour yet.
Integration hell
Before continuous integration, teams often worked in isolation for weeks or months and then had an “integration phase” before a release. Everyone merged at once, the build broke in a dozen places, and the team spent days or weeks making the pieces fit. People called it integration hell, and it was routinely the least predictable part of a project.
The cause is simple. While two people work apart, the code each of them is building on goes stale. Alice renames a function. Bob calls the old name in ten new places. Neither knows until they merge. The longer the gap, the more such collisions build up, and the less either remembers why they made each change.
A merge that went wrong
I reproduced this with Git in a scratch repository. A tiny shop.py had a price() function. Alice branched and made six commits: five new functions and a price change to qty * 12. Bob branched from the same point and made six commits: five new functions of his own and a change to round the price. Alice merged first, cleanly. Then Bob:
$ git merge bob
Auto-merging shop.py
CONFLICT (content): Merge conflict in shop.py
Automatic merge failed; fix conflicts and then commit the result.
git diff showed two conflict regions. One was the price line:
++<<<<<<< HEAD
+ return qty * 12 # new list price
++=======
+ return round(qty * 10, 2)
++>>>>>>> bob
Look at what Bob wrote: rounding applied to a price that no longer exists. Resolving this is not a matter of keeping both lines. Someone has to understand both intents and write round(qty * 12, 2). The second region was the five-function blocks both had appended at the end of the file. Git can’t order them for you.
Then I replayed the same work in small steps. Alice committed one function and pushed. Bob pulled before writing his, so his change sat on top of hers. When Alice repriced, Bob pulled again and his copy showed return qty * 12 before he had written a line of rounding code. No conflict, because Bob never built on a stale copy.
Six commits is a toy. Real branches run to weeks and dozens of files, and the conflicts that hurt are not textual. They are two pieces of code that merge cleanly and then disagree at runtime.
What continuous integration actually means
The term comes from Extreme Programming in the late 1990s, and Martin Fowler’s article on it is still the standard reference. The practice has three parts:
- Everyone integrates into a shared mainline at least daily. Not into a long-lived feature branch. Into
main. - Every integration is verified automatically: a build and a fast test suite run on each merge.
- A broken mainline is the team’s top priority. It is fixed or reverted in minutes, and nobody merges on top of red.
Notice that only the second part involves a tool. A CI server that runs tests on month-old feature branches gives you automation, but the code is still not being integrated. That is the point Dave Farley makes in the video: CI and long-lived feature branches are largely in tension.
Trunk-based development is the branching model that fits. Branches, if you use them, live for hours to a day or two and merge through a short pull request.
Making daily integration possible
The usual objection is “my feature takes two weeks”. The work can take two weeks. The integration doesn’t have to wait.
- Small slices. Merge the database column first, then the API that writes it, then the UI. Each step is shippable and keeps the build green.
- Feature flags. Merge incomplete code switched off. Production runs it only when you flip the flag. Feature flags in practice covers the code side.
- Branch by abstraction. Put an interface in front of the old implementation, build the new one behind it, and switch over when it is ready.
This also separates deploying code from releasing a feature, an idea that comes back in the delivery group.
Team rules that make it stick
CI is a social contract. The habits that make it work:
- Run the fast tests locally before pushing.
- Wait for the CI result before moving on, so you are around if it fails.
- If you broke the build, fix it or revert your change within about ten minutes. Reverting is not a failure. It is the fastest way back to green.
- Keep the build fast. If verification takes an hour, people batch their changes to avoid waiting, and integration slows down again. The next lessons cover how pipeline stages keep feedback fast.
About the video
Dave Farley’s “Continuous Integration vs Feature Branch Workflow” (Modern Software Engineering, 2021, about 17½ minutes) explains, per its description, why CI and feature branching are mutually exclusive in most cases, then describes three approaches to keeping software working as it changes. Its chapters run from what CI is and the problem with branching through committing frequently to separating deploy from release, feature flags and branching on behaviour. Farley co-wrote Continuous Delivery, so this is a primary source, if an opinionated one. I had no transcript, so this is from the title, description and chapters. English was judged from the same metadata. His “Top 10 Rules For Continuous Integration” and IBM’s six-minute introduction are under deeper.
Where this fits
For what CI looks like on one real app, see continuous integration for a full-stack repo, and for the GitHub Actions syntax, workflows, triggers, jobs and steps. Next here: what the automated verification is made of, in anatomy of a pipeline: stages, jobs and gates.
Check yourself
Your team has a CI server that runs tests on every branch, but feature branches live for three weeks. Are you doing continuous integration?
No. The tests run continuously, but the code is not integrated with everyone else's until the branch merges. Conflicts and broken assumptions pile up for three weeks and surface all at once.
Why does merging small changes often lead to fewer merge conflicts overall?
Each person starts from code that already includes everyone else's recent work, so they build on the current design instead of an old copy. Any conflict that does occur is small and fresh in both authors' minds.
The mainline build has been red for two hours and three people have merged on top of it. What went wrong?
The team broke the core CI rule. A red build should be fixed or the breaking change reverted immediately, and nobody should merge on top of it, because every new change makes the failure harder to isolate.
How can you integrate daily when a feature takes two weeks to build?
Merge it in small slices that keep the build green, hide incomplete behaviour behind a feature flag, or add new code alongside the old and switch over at the end.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.