The issue opens pre-filled with this page title and URL.
A startup with three developers and a single service does not need the
same pipeline architecture as a bank with 200 teams and hundreds of
microservices. The first case runs on a single pipeline that builds,
tests and deploys; the second requires splitting repositories, detecting
changes and coordinating dozens of pipelines. There is no "best" pipeline,
only the one that fits your context.
This guide presents the main families of pipeline architectures and their
trade-offs: branching strategies, monorepo vs polyrepo, promotion vs
rebuild and the application/infrastructure split. The goal is to give you
the criteria to choose yours or make it evolve.
What you will learn
Choose between a pipeline per branch (GitFlow) and trunk-based according to your cadence
Compare monorepo, polyrepo and a hybrid strategy
Apply artifact promotion rather than rebuilding
Separate application and infrastructure pipelines, then coordinate them
Recognise the advanced forms: diamond, matrix, conditions
Before you start: what are we talking about?
When we talk about "pipeline architecture", we mean how to organise all your
pipelines, not the content of a single pipeline. The key questions
are:
How many pipelines do you have? One for everything? One per service? One
per branch?
How are they triggered? On every commit? Only on some branches?
How do artifacts flow? Rebuilt at each stage? Promoted from one
environment to the next?
These choices depend on three main factors:
Factor
Questions to ask
Team structure
How many developers? How many teams? Do they work on the same code?
Branching strategy
Do you use GitFlow with several long-lived branches? Or does everyone work on main?
Deployment model
Do you deploy once a month or 50 times a day? Do you have several versions in production?
Swipe to see more
Branching strategies: how to organise your code
The way you organise your Git branches directly shapes the structure of your
pipelines. Two broad philosophies are at odds.
Pipeline per branch (GitFlow approach)
The principle: you maintain several "long-lived" branches that live in
parallel for weeks or months. Each branch has a precise role and its own
pipeline.
Developers work on branchesfeature/* (new features)
These branches are merged into develop, an integration branch
When preparing a release, a release/X.Y branch is created
After approval, the release is merged into main (production)
Each long-lived branch has its own pipeline with different behaviours
Example configuration:
Branch
What the pipeline does
feature/*
Unit tests, lint, static analysis
develop
Tests + deployment to the development environment
release/*
Full tests + staging deployment + acceptance tests
main
Production deployment (often with manual approval)
Swipe to see more
Advantages:
Clear separation: each environment matches a branch, easy to understand
Fine control: you decide exactly what goes to production and when
Parallel versions: you can maintain several versions in production (1.0,
1.1, 2.0)
Drawbacks:
Complexity: several pipelines to maintain, which may diverge
Painful merges: the longer branches live, the more conflicts there are
Delay: weeks can pass between writing code and putting it in production
Ideal context: teams with planned release cycles (monthly, quarterly),
products with several versions supported in parallel (software installed at
customers' sites, mobile applications).
Trunk-based development: everything on a single branch
The principle: everyone works directly on the main branch (main or
trunk). Feature branches exist, but they are very short, a few hours, not a
few days.
Trunk-based development: branches feature/a, feature/b and feature/c, which live under 24 h, merge into main, which triggers CI then deployment to staging and production.Lifetime: under 24 hfeature/afeature/bfeature/cmainCIstagingprod
A developer creates a feature/xxx branch from main
They work for a few hours (rarely more than a day)
They open a pull request, which is reviewed quickly
As soon as it is merged into main, the pipeline is triggered
If all the tests pass, the code can go to production automatically
The key: feature flags
How do you deploy code to production if it is not finished? Thanks to
feature flags (or "feature toggles"), switches in the code that enable or
disable a feature.
# Simplified feature flag example
if feature_flags.is_enabled("new_payment_interface"):
show_new_interface()
else:
show_old_interface()
The code is in production, but the feature is "switched off". When it is
ready, it is enabled for a few users (canary), then for everyone.
Advantages:
True continuous integration: code is integrated several times a day, not
once a week
No "merge hell": short branches mean few conflicts
Fast feedback: you know within hours whether your code works with
everyone else's
Drawbacks:
Strict discipline: every commit on main must be production quality
Feature flags required: extra infrastructure to manage
Excellent test coverage required: without reliable tests, it is chaos
Ideal context: mature teams practising continuous deployment, SaaS
products with a single version in production.
Comparison: which approach should you choose?
The table compares the two models row by row. The decisive row is
merge frequency: it determines everything else. Merges days apart
mechanically lead to long-lived branches, hence conflicts, hence a less
pressing need for tests; several merges a day impose feature flags and solid
test coverage. Read that row first, then go down.
Aspect
Pipeline per branch (GitFlow)
Trunk-based
Merge frequency
Days or weeks
Hours
Number of pipelines
Several (one per branch type)
One
Feature flags
Optional
Required
Git conflict risk
High (long-lived branches)
Low (short branches)
Time to production
Days or weeks
Minutes or hours
Pipeline complexity
Medium to high
Simple
Testing needs
Important
Critical
Swipe to see more
How to choose?
You ship once a month or less → GitFlow is acceptable
You ship several times a week → consider trunk-based
You have several versions in production → GitFlow is often necessary
You run a SaaS with a single version → trunk-based fits better
Monorepo vs polyrepo: where to put your code
Beyond branches, another question structures your pipelines: how many Git
repositories do you have?
Monorepo: everything in one repository
The principle: all your services, libraries and tools share the same Git
repository. Google, Meta and Microsoft use this approach for a large part of
their code.
monorepo/
├── services/
│ ├── api/ # Backend service
│ ├── frontend/ # Web application
│ └── worker/ # Asynchronous processing
├── libs/
│ ├── auth/ # Authentication library
│ └── utils/ # Shared utilities
└── infra/
├── terraform/ # Infrastructure as Code
└── k8s/ # Kubernetes manifests
The challenge: not rebuilding everything on every commit
If someone changes the frontend README, there is no point rebuilding the API.
The pipeline must be "smart" and detect what changed.
Commit changes: services/api/src/users.py
Pipeline analyses dependencies:
✓ services/api → rebuild (file changed)
✓ libs/auth → check (the API may use it)
✗ services/frontend → skip (not affected)
✗ services/worker → skip (not affected)
Advantages:
Atomic refactoring: a single PR can change the API, the frontend and the
libs, and everything stays consistent
Natural code sharing: common libraries live in the same repository, no
need to publish them
Version consistency: every service uses the same version of the libs
Drawbacks:
Complex pipeline: detecting what changed requires tooling (Nx,
Turborepo, Bazel)
Long clone time: the repository can become very large
Complicated permissions: hard to restrict access to some parts
Common monorepo tools:
Tool
Language/Ecosystem
Strength
Nx
JavaScript/TypeScript
Excellent for frontend projects
Turborepo
JavaScript/TypeScript
Simple, fast, distributed cache
Bazel
Polyglot
Very powerful, but steep learning curve
Pants
Python, Go, Java
Good alternative to Bazel
Swipe to see more
Polyrepo: one repository per service
The principle: each service, each library has its own Git repository and
its own pipeline.
github.com/acme/api # Its own repo, its own pipeline
github.com/acme/frontend # Same
github.com/acme/worker # Same
github.com/acme/libs-auth # Published as a package (npm, PyPI...)
github.com/acme/infra # Separate Terraform
Advantages:
Simple pipeline: each repository has a pipeline that always does the same
thing
Autonomous teams: the API team can deploy without waiting for the
frontend team
Clear permissions: easy to grant access to one repository without
exposing the rest
Drawbacks:
Version coordination: is API v2.3 compatible with frontend v1.8?
Duplication: pipeline configuration is often copy-pasted between
repositories
Painful refactoring: changing a shared interface means several PRs in
several repositories
The "dependency hell" problem:
In a polyrepo, shared libraries are published as packages (npm, PyPI,
Maven...). This raises questions:
When libs-auth publishes a new version, who updates it in each service?
How do you make sure every service is compatible?
What do you do if a service is stuck on an old version?
Hybrid strategy: the best of both worlds?
Few organisations are 100% monorepo or 100% polyrepo. Most decide
type of code by type of code: business services benefit from being
grouped, while infrastructure and widely distributed libraries follow life
cycles different enough to justify their own repository. The following table
sums up this common split.
Type of code
Strategy
Why
Business services
Monorepo
Atomic refactoring, consistency
Infrastructure
Separate repo
Different life cycle, distinct permissions
Widely shared libs
Separate repos + versioning
Reuse outside the organisation
Swipe to see more
Concrete example:
github.com/acme/platform # Monorepo: API + frontend + workers
A crucial question many teams overlook: is the artifact you deploy to
production the same as the one you tested?
The rebuild problem
A common (and risky) situation:
# ❌ Rebuilding for each environment: to avoid
# Staging pipeline
staging:
script:
- npm install
- npm run build
- docker build -t app:staging .
- docker push registry/app:staging
- kubectl apply -f k8s/staging/
# Production pipeline (a few days later)
production:
script:
- npm install# Careful: dependency versions may have changed
- npm run build# Careful: potentially different result
- docker build -t app:production .
- docker push registry/app:production
- kubectl apply -f k8s/production/
Why is it a problem?
Between the test in staging and the deployment to production, three
things may have changed:
An npm dependency may have been updated (even a patch)
The Docker base image may have changed
A build tool may have evolved
Result: what you deploy to production is not exactly what you tested. And
when it breaks, there is no way to know why.
The solution: artifact promotion (build once, deploy many)
The principle: build the artifact only once, then promote it from
environment to environment without rebuilding it.
Artifact promotion: the image built once with docker build -t app:abc12 is promoted, unchanged, from dev to staging then to prod.same imagesame imagesame imagebuilddocker build -t app:abc12devstagingprod
Build: the artifact is built with a unique tag (e.g. app:abc123)
Test in dev: app:abc123 is deployed to development
Test in staging: the sameapp:abc123 is deployed to staging
Production: still the sameapp:abc123 is deployed to production
The only thing that changes between environments: the configuration
(environment variables, secrets).
Concrete example:
# Step 1: single build
build:
script:
- docker build -t app:$CI_COMMIT_SHA .
- docker push registry/app:$CI_COMMIT_SHA
# Step 2: staging deployment (same image)
staging:
script:
- helm upgrade app ./chart \
--set image.tag=$CI_COMMIT_SHA \
--set env=staging \
-f values-staging.yaml
# Step 3: production deployment (still the same image)
production:
script:
- helm upgrade app ./chart \
--set image.tag=$CI_COMMIT_SHA \
--set env=production \
-f values-production.yaml
when: manual# Approval required
Advantages of promotion:
Aspect
Rebuild
Promotion
Reproducibility
Uncertain
Guaranteed
Deployment time
Long (rebuild)
Fast (just deploy)
Rollback
Rebuild the old version
Redeploy the old tag
Confidence
"It worked in staging..."
"It's the same artifact"
Swipe to see more
Prerequisites for promotion:
For this to work, your application must:
Separate the build from the config: no hard-coded values (URLs,
credentials)
Accept configuration at runtime: environment variables, mounted config
files
Have a reliable artifact registry: where images are stored between
stages
Application pipeline vs infrastructure pipeline
So far, we have mostly talked about pipelines that deploy application code
(API, frontend). But infrastructure can, and should, also be managed by
pipelines.
Application pipeline
This is the one most teams already have: it turns a code commit into a
deployed version. Its characteristics all stem from the fact that it runs
often and only affects a limited scope, which allows fast feedback and a
contained risk on each run.
What it deploys: your application code, API, frontend, workers, jobs.
Application pipeline: lint, test, Docker image build, then deployment to Kubernetes.linttestbuilddockerdeployk8s
It applies the changes described in Infrastructure as Code and is the
reverse of the previous one: it runs rarely but its blast radius is
wide, since a single change can affect every hosted service. This asymmetry is
what justifies handling it separately, with its own guardrails and its own
approvals.
What it deploys: the resources your application runs on, networks,
databases, clusters, DNS.
Infrastructure pipeline: validate (fmt, tflint), plan, manual approval, then apply.validatefmt/tflintplanapprove(manual)apply
Triggered by Infrastructure as Code changes (Terraform, Pulumi)
Lower frequency (a few times a week)
Potentially wide impact (may affect several services)
Separate or integrate?
The table weighs the two options. Separation limits the blast radius and
keeps permissions distinct; a single pipeline buys atomicity at the
cost of complexity and of a higher risk when it fails.
Recommendation: separate the pipelines, but coordinate them.
Infrastructure changes less often than code. Mixing the two creates
heavy pipelines where a button colour change triggers a Terraform
check.
How to coordinate?
Triggers: the infra pipeline triggers the app pipeline on success
GitOps: tools such as Argo CD or Flux detect changes and deploy
Explicit dependencies: the app pipeline checks that the infra is up to
date before deploying
Advanced architectures
Once the basics are mastered, some teams adopt more sophisticated patterns.
Diamond pipeline: maximum parallelism
The principle: run as many jobs as possible in parallel, then converge
again before the next step.
Why "diamond"? The shape of the graph looks like a diamond: a starting
point, a divergence (parallelism), a convergence, then divergence/convergence
again.
Diamond pipeline: checkout fans out to lint, test and scan in parallel, which converge on build; build fans out again to the dev, staging and prod deployments, staging carrying an approval.checkoutlinttestscanbuilddevstagingprod(approval)
Shorter total time: lint, tests and scan run at the same time
Fast feedback: if the lint fails, you know without waiting for the tests
to finish
Optimised resources: runners work in parallel
Careful: all parallel jobs must succeed to move to the next step. One
failure = blocked pipeline.
Matrix pipeline: testing every combination
The problem: your library must work with Python 3.11, 3.12, 3.13 and 3.14,
on Ubuntu, macOS and Windows. That makes 12 combinations to test.
The solution: the matrix generates every job automatically.
test:
strategy:
matrix:
# Quoted versions: without quotes, YAML reads 3.10 as the number 3.1
python: ["3.11", "3.12", "3.13", "3.14"]
os: [ubuntu-24.04, macos-26, windows-2025]
# Result: 4 versions × 3 OSes = 12 parallel jobs
Two details of this snippet avoid discreet failures. The versions are
quoted, because YAML reads 3.10 as the number 3.1, and the matrix would
then test a version that does not exist. The systems are named by their
version (macos-26, windows-2025) rather than by a -latest label, which
changes target without warning and makes a failure hard to reproduce.
Use cases:
Open source libraries (multi-version compatibility)
Desktop applications (multi-OS)
Compatibility checks before a dependency upgrade
Conditional pipeline: adapting to the context
The principle: some jobs only run when certain conditions are met.
Common examples:
Condition
Behaviour
Branch = main
Deploy to staging, then production (with approval)
Branch = feature/*
Deploy to an ephemeral environment, destroy after 24h
Files changed in docs/
Skip the tests, only rebuild the documentation
Tag created (v*)
Create a release, publish the packages
Swipe to see more
Why is it useful?
Resource savings: no need to test everything if only the docs changed
Adapted feedback: a feature branch does not need to deploy to production
Flexibility: different behaviours depending on the context without
multiplying pipelines
Choosing your architecture: decision guide
Faced with all these options, how do you choose? Here is a guide based on
concrete questions.
Question 1: how many teams work on the code?
The number of teams sharing the code mainly decides between monorepo or
polyrepo. As long as a single team touches everything, a monorepo stays
simple to tool. Beyond a few teams, either you invest in an incremental
build tool, or you split into autonomous repositories to make the teams
independent.
Situation
Recommendation
1 team (< 10 people)
Simple monorepo, trunk-based possible
2-5 teams
Monorepo with tooling (Nx, Turborepo) or light polyrepo
10+ teams
Polyrepo likely, or monorepo with dedicated infrastructure
Swipe to see more
Question 2: what deployment frequency?
Deployment cadence decides between GitFlow and trunk-based. The more often
you ship, the less tenable long-lived branches become: the cost of
merges ends up exceeding the benefit of the control they bring. From a
weekly rhythm, artifact promotion stops being a comfort and becomes a
necessity, or you risk deploying a binary different from the one that was
tested.
Question 3: do you have several versions in production?
This question is often the most constraining, because it does not depend on
your preferences but on your product. Software installed at the customer's
site or a mobile application requires maintaining several versions in
parallel, hence release branches and pipelines per branch. A SaaS where all
users are on the same version lifts this constraint and opens the way to
trunk-based.
Situation
Recommendation
No (SaaS, a single version)
Trunk-based, single pipeline
Yes (installed software, mobile app)
Release branches, pipelines per branch
Swipe to see more
Question 4: how mature is your testing?
Testing maturity acts as a guardrail on everything above. Trunk-based
and continuous deployment only work if your automated tests actually catch
regressions; otherwise, every merge on main becomes a gamble. Be honest
on this point: investing in test coverage before speeding up deployments avoids
turning a fast pipeline into an incident dispenser.
Level
Recommendation
Few or no automated tests
Stay with simple pipelines, invest in tests first
Critical paths covered
Trunk-based possible, with caution
Excellent coverage + integration tests
Continuous deployment possible
Swipe to see more
The anti-pattern: copying without understanding
"Netflix does trunk-based with continuous deployment, we should do the same!"
No. A company of that size brings together four conditions that make this
model sustainable: whole teams dedicated to tooling, years of iteration on
its practices, a mature testing and feature flag infrastructure, and a SaaS
context with a single version in production.
Copying its architecture without reproducing these four conditions means
inheriting the complexity without the foundation that makes it
sustainable: fragile pipelines, failed deployments and a team that
spends its time fixing the tooling instead of shipping.
The right approach:
Start simple: a linear pipeline that builds, tests, deploys
Identify the pain points: what really slows you down?
Evolve gradually: add complexity when you need it
Measure: pipeline time, deployment frequency, failure rate
Key points
Pipeline architecture reflects your context: team structure, branching
strategy, deployment model. There is no universal solution.
Trunk-based vs GitFlow: short branches mean fewer conflicts and fast
feedback, but require discipline and feature flags. Long-lived branches
give more control, but painful merges.
Monorepo vs polyrepo: a monorepo eases refactoring and consistency, but
requires tooling. A polyrepo gives autonomy, but complicates coordination.
Promotion > rebuild: build the artifact once, deploy it everywhere. What
you test must be exactly what you deploy.
Separate app and infra: different cycles, different permissions,
different risks. Coordinate, but do not mix.
Start simple, add complexity when needed: the perfect pipeline does not
exist on day 1. Iterate based on real problems.
Knowledge check
Check that the essentials of this lesson are in place. The questions only
cover what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
6 questions
6 min
70% to pass
How it works
The timer starts when you click Start
Multiple choice, true/false and short answer questions
You can move between questions
Detailed results are shown at the end
Starts the quiz and the timer
⏱️--:--
0 / 6
Review
(0/0)
--:--
0%
Result saved on this device. It will be sent to your account at the next sync. Sync now
0Correct
0To review
0:00Time
-Level
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.