Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 15 min · revision 3

Integrating continuously: small batches and a green main

Learn the team discipline behind continuous integration: small batches, trunk-based development, less merge debt and a main branch that is kept green and deployable.

Contentsand lesson path

What you will learn

  • Gate merges with required status checks and branch protection, and trace a failing run from its logs to the root cause.

Prerequisites: Git Workflow, Build & Test Pipeline

01. Why it matters

When several people change the same code, writing each change is rarely the hard part. Combining the changes is. The longer two changes stay apart, the more they clash, and the later anyone finds out. Continuous integration is the team habit that keeps this combining step small and frequent, so a clash shows up within minutes, while the author still remembers the change. This lesson covers the habit itself (small changes merged at least daily), the techniques that make it possible (trunk-based development and feature flags) and the rule that keeps it working (a broken main is fixed before anything else).

02. Continuous integration is a team habit, not a tool

Many people use the term "continuous integration" (CI) to mean a hosted automation service, such as GitHub Actions, GitLab CI or Jenkins, that runs the tests whenever someone opens a pull request. That service is only the tool. Kent Beck's Extreme Programming and Martin Fowler's writing, which made the term widely known, describe CI as a team practice: an agreement about how often people share their work. The tool supports the practice, but it cannot replace it.

By definition, Continuous Integration requires every developer on an engineering team to integrate their working code into the shared mainline branch (often main or trunk) at least once per day—and ideally multiple times per day. Every integration into mainline is verified by an automated build and test sequence that completes within minutes. If developers work in isolated long-lived feature branches for two weeks and only trigger automated tests upon submitting a massive pull request at the end of the sprint, they are practising what some call Continuous Isolation, not Continuous Integration.

The main purpose of CI is to keep merge debt and integration surprises small. When multiple engineers work on parallel branches for days or weeks without merging, their branches drift further apart every day, and the cost and risk of merging them grows faster than the time spent apart: each branch has more changes, and each change can clash with more of the other branches' changes. When the branches are finally merged, teams hit "merge hell": semantic merge conflicts, where the lines merge cleanly but the business logic or data contracts no longer fit together, and the break may show only in production.

When a team really works this way, people learn within minutes, not weeks, that a change broke something. The author finds out while the code is still fresh in their mind, so the failure is much cheaper to find and fix.

03. Trunk-based development instead of long-lived branches

Many teams have used Gitflow, a branching model with several long-lived branches (develop, release, feature and hotfix). Gitflow suits a product that ships a planned release every few months, because each release gets its own branch and its own sign-off steps. For teams that deploy often, it causes problems:

  • Delayed integration feedback: a bug introduced on day one of a feature branch stays invisible to other engineers until weeks later, when develop is updated.
  • Cherry-picking and drift: an urgent hotfix has to be copied back through release and feature branches, and the copies drift apart.
  • Overloaded reviewers: a pull request with forty changed files and 2,500 lines is too big to read carefully, so it tends to get a quick "LGTM" (looks good to me) approval that lets defects into mainline.

Many teams that deploy often use Trunk-Based Development (TBD) instead. In TBD, all developers commit either directly to main or through short-lived feature branches that merge into main within one or two days maximum.

To ship incomplete features into main without exposing unready capabilities to end users, teams use two patterns: Feature Flags and Branch by Abstraction.

  • Feature flags (toggles): separate deploying code from releasing a feature. Incomplete code paths are merged behind a runtime switch that stays off for users, so the code is integrated and tested while the feature stays hidden.
  • Branch by abstraction: when replacing a major subsystem (such as an ORM layer or payment provider), developers introduce an abstract interface in mainline, implement the new component side-by-side with the old one, route traffic incrementally, and then remove the old implementation once parity is verified.
Python · Decoupling deployment from release via runtime feature flags
import os

class FeatureToggleService:
    @staticmethod
    def is_enabled(feature_key: str, default: bool = False) -> bool:
        # In production, query LaunchDarkly, Unleash, or Redis config
        flag_val = os.getenv(f"FEATURE_{feature_key.upper()}", "")
        if flag_val.lower() in ("true", "1", "yes"):
            return True
        if flag_val.lower() in ("false", "0", "no"):
            return False
        return default

def process_checkout(cart_data: dict) -> dict:
    # Route traffic dynamically without branching merge conflicts
    if FeatureToggleService.is_enabled("NEW_PAYMENT_ENGINE"):
        return execute_v2_checkout(cart_data)
    return execute_legacy_checkout(cart_data)

def execute_v2_checkout(cart_data: dict) -> dict:
    return {"status": "success", "engine": "v2", "cart": cart_data}

def execute_legacy_checkout(cart_data: dict) -> dict:
    return {"status": "success", "engine": "legacy", "cart": cart_data}

04. Keeping main green: stop the line

Trunk-based development works only if the shared mainline stays green: it builds, its tests pass and it can be deployed. When it breaks, fixing it comes before any other work.

When a commit breaks main, many teams apply the stop-the-line rule, named after the Andon cord of the Toyota Production System:

  • Drop current feature work: restoring a green main becomes the team's top priority, and new pull requests wait until it is green.
  • Revert first, investigate later: if the fix is not quick and obvious, revert the offending commit with git revert. Many teams use a time box, such as ten minutes, to decide; the exact number is a team agreement, not a standard. A revert is usually the fastest way back to green and unblocks colleagues while the author diagnoses the failure locally. Check that it applies cleanly against later commits and that it does not undo a schema or data change that later commits or a running release depend on; in that case a small forward fix is safer.
  • Avoid broken windows: a red build left for hours signals that failures are acceptable. People stop paying attention to alerts, new bugs pile up behind the first one, and the pipeline stops being a safety net anyone trusts.

Teams that work this way often track two numbers: lead time for changes (from commit to production) and time to restore a red mainline. A green main also means an urgent fix can ship from it without dragging along someone else's untested, half-finished work.

05. Check your understanding

Practice check · 3 questions

Integration frequency, unfinished work and a red main

Three questions on everyday continuous integration habits.

Q1. Why does the formal Continuous Integration discipline mandate integrating code into the shared mainline branch at least daily, rather than maintaining feature branches for the duration of a multi-week sprint?
Q2. The checkout code from this lesson is deployed with its `FeatureToggleService`. To release the new engine, an operator sets `FEATURE_NEW_PAYMENT_ENGINE=on` on the servers and restarts them. Which engine does `process_checkout` use, and why?
Q3. A commit merged to the `main` branch fails a critical database integration test, turning the main build red. What does continuous integration discipline expect the team to do?
Practice only: not graded, not saved, not evidence.

06. Apply it

Agree these practices with your team:

  • Keep branches to a day or two: if a branch needs more than two days, split the work into smaller tasks.
  • Use feature flags for large features: merge small steps behind a runtime flag instead of keeping one large branch.
  • Agree a revert time box: agree as a team how long you try a fix before reverting (many teams use about ten minutes), and check that the revert does not undo a migration or data change before you push it.
  • Treat a broken main as stop-the-line: do not merge new feature PRs while main is red, so new failures do not pile up on top of the first.
  • Measure integration frequency: count merges to main per week for the team, and watch the trend rather than ranking individuals.

07. Review prompt

Without looking back: what is the difference between continuous integration as a team practice and a CI service, and what does "continuous isolation" describe? Why do smaller pull requests usually wait less and break less? How does a feature flag let you merge unfinished work into main? When main turns red, what does the team do first, and when does it revert?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check