SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
  • Deployment Strategies Overview
  • CI/CD Pipelines
  • Rolling Deployments
  • Blue-Green Deployments
  • Canary Releases
  • Feature Flags
  • A/B Testing Infrastructure
  • Schema Migrations
  • Rollbacks and Immutable Infrastructure
  • Multi-Region and Active-Active
  • Infrastructure as Code (Terraform)
  • Auto-Scaling Policies
  • Zero-Downtime Deployment
  • Chaos Engineering
  • Shadow Traffic and Dark Launches
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Operations and Security/Deployment Patterns

CI/CD Pipelines

An automatic line that builds, tests and ships every code change.

⏱ 13 min readBeginnerMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A CI/CD pipeline is an automatic line that takes every code change, builds it, tests it and (if everything is fine) ships it. No one has to remember the steps.

  • CI (Continuous Integration): developers merge small changes often, and each merge is built and tested automatically.
  • CD (Continuous Delivery): every passing change is ready to release at any time. A person presses the button.
  • CD (Continuous Deployment): every passing change goes to production by itself, with no button.

02Concept: What is it?

Without a pipeline, a release means someone follows a checklist by hand: build on a laptop, run some tests, copy files to a server. Hand steps are slow and easy to get wrong, so teams release rarely, and each release is big and scary.

A pipeline turns that checklist into code that runs the same way every time. A change goes in at one end. At each stage a check runs. If a check fails, the line stops and the author gets a red build. If all checks pass, the change moves forward.

A typical pipeline
πŸ’ΎCommitpush to Git
→↓
πŸ”¨Buildmake a package
→↓
πŸ§ͺTestunit, integration
→↓
πŸ›‘οΈScansecurity
→↓
🎭Stagingtry it
→↓
πŸš€Productionrelease
Cheap and fast checks come first. Slow and expensive checks come later, so most mistakes are caught early.
🧠CI is about the team, CD is about the release
CI keeps the code healthy by merging often and testing every time. CD keeps the release routine by always being ready to ship. The two work best together.

03Real-Life Example

🍡A Factory Conveyor Belt with Inspectors
A bakery makes thousands of loaves. Each loaf goes along a belt. One inspector checks the dough. The next checks the shape after baking. A third checks the weight. A loaf that fails is pulled off the belt at once, with a note on what went wrong. Only loaves that pass every check go into the delivery van. The baker does not have to inspect each loaf by hand.
Bakery
Pipeline
A loaf
A code change (commit)
The belt
The pipeline
An inspector
A check: tests, lint, security scan
Pulling a bad loaf off the belt
A failed build, shown to the author
The delivery van
Deployment to production
One tray of dough, used all along the belt
One build artifact, promoted through the stages
Running a shift every time a loaf is made
The pipeline runs on every commit
Fast feedback
πŸ‘©β€πŸ’»Developersmall change
→↓minutes
πŸ”΄Red buildwhat broke
→↓fix
🟒Green buildmerge

04Why Do We Need It?

⚑Fast feedback
A broken change is found in minutes, while the author still remembers it.
🧯Fewer big bangs
Small, frequent merges mean small, easy-to-fix problems, not a huge merge at the end.
πŸ”Repeatable
The same steps run the same way every time, on every machine.
πŸš€Frequent releases
When shipping is safe and automatic, teams ship small changes many times a day.
πŸ›‘οΈBuilt-in safety
Tests and security scans run on every change, not only when someone remembers.
πŸ“œAn audit trail
You can see who changed what, which checks passed, and what is running now.
A pipeline makes the safe way the easy way. Every change is checked the same way, and shipping becomes boring.

05Where Do We Use It?

πŸ™Hosted CI services
GitHub Actions, GitLab CI, CircleCI and similar tools run pipelines from a file in your repository.
πŸ—οΈSelf-hosted servers
Jenkins and similar tools that you run on your own machines.
☁️Cloud-native tools
AWS CodePipeline, Google Cloud Build and Azure DevOps Pipelines.
πŸ”„GitOps
A tool such as Argo CD or Flux watches a Git repo and makes the cluster match it.
🧱Infrastructure code
Pipelines also plan and apply changes to infrastructure (Terraform and similar).
πŸ“±Mobile and libraries
Build the app, sign it, run tests, and upload to a store or a package registry.

06Types / Parts / How It Works

CI, continuous delivery and continuous deployment

TermWhat is automaticWho decides to releaseNeeds
Continuous IntegrationBuild and test on every mergeA person, laterGood automated tests
Continuous DeliveryEverything up to a release-ready packageA person presses a buttonTests plus a repeatable release process
Continuous DeploymentEverything, including the releaseNobody: every green change shipsStrong tests, monitoring and fast rollback

Common pipeline stages

StageWhat it doesTypical speed
Lint and static analysisChecks style and finds suspicious code without running itSeconds
BuildCompiles the code and builds one versioned package (artifact or image)Minutes
Unit testsTest small pieces of code in isolationMinutes
Integration testsTest several parts working together, often with real databasesSlower
Security scansLook for known vulnerable libraries, leaked secrets and unsafe codeMinutes
Staging and smoke testsRun the package in a production-like place and check the basicsMinutes
DeployRoll the same package out with a strategy such as rolling or canaryMinutes
Post-deploy checksWatch error rates and latency, and roll back if neededOngoing
πŸ’‘Build once, promote many times
Build the package one time and move that same package through staging and production. If you rebuild for each environment, what you tested is not what you ship.
VisualizerSend a commit through the pipelinePick a kind of mistake, then switch checks on and off. See which stage stops it, how long the feedback takes, and what happens when no stage can catch it. Try continuous delivery against continuous deployment.
What is wrong with this commit?
Last step before production
Checks in the pipeline (click to switch on or off)
πŸ”¨
Build
passed (3 min)
β†’
πŸ§ͺ
Unit tests
FAILED
β†’
πŸ”—
Integration tests
not reached
β†’
πŸ›‘οΈ
Security scan
not reached
β†’
🎭
Staging + smoke test
not reached
β†’
πŸš€
Production
not reached
Feedback after
7 min
until the red build
Caught at
Unit tests
before users
Cost to fix
2x
illustrative
A function returns the wrong total. The "Unit tests" stage caught it after 7 minutes. The developer gets a red build while the change is still fresh, and no user was affected. The fix costs about 2x the base effort (illustrative).

A simplified model. Stage times and the cost multipliers are made-up round numbers for illustration, not measurements. A real pipeline also builds the package once and promotes the same one through every stage.

07How to Use It / Steps / Implementation

Setting up a good pipeline

  1. 1
    Keep the pipeline in code
    Store it as a file in the repository (pipeline as code). Reviews and history then work for it like any other code.
  2. 2
    Run on every change
    Trigger on each push and pull request. Block merges when the pipeline is red.
  3. 3
    Fail fast
    Put the cheapest, quickest checks first (lint, build, unit tests), so a typo does not wait 20 minutes for a result.
  4. 4
    Build one artifact
    Create a single versioned package, store it in a registry, and deploy that same package everywhere.
  5. 5
    Test in layers
    Many fast unit tests, fewer integration tests, and a small set of end-to-end tests. Keep tests reliable, because flaky tests train people to ignore red builds.
  6. 6
    Add security and quality gates
    Scan dependencies and secrets, and add rules such as minimum test coverage if your team agrees on them.
  7. 7
    Deploy with a strategy
    Use rolling, blue-green or canary. After deploying, check health numbers and roll back automatically if they get worse.
  8. 8
    Keep it fast
    Cache dependencies, run steps in parallel and keep the main pipeline to minutes, not hours.
πŸ’‘Treat a red build as stop-the-line
When the main branch is red, fixing it comes first. If a team lives with a red pipeline, the pipeline stops protecting them.
⚠️Protect the pipeline itself
A pipeline can reach production and holds secrets. Use short-lived credentials, limit who can change it, and never print secrets in logs.

08Key Terms to Know

TermMeaning in easy words
CIContinuous Integration: merge often, and build and test every change automatically
CDContinuous Delivery (always ready to release) or Continuous Deployment (releases by itself)
PipelineThe ordered set of automatic stages a change goes through
Stage / jobOne step in the pipeline, such as build or test
ArtifactThe built, versioned package that gets deployed (an image, a JAR, a zip)
GateA check that must pass before the change moves on
Flaky testA test that sometimes fails for no real reason
Smoke testA tiny check that the basics work after a deploy
Pipeline as codeThe pipeline described in a file stored with the source code
Trunk-based developmentEveryone merges small changes into one main branch very often
GitOpsGit is the source of truth, and a tool keeps the running system equal to it

09Pros, Cons and Trade-offs

βœ… Pros
  • Problems are found within minutes
  • Releases are repeatable and low-stress
  • Teams can ship small changes often
  • Security and quality checks happen on every change
  • A clear record of what shipped and when
⚠️ Cons
  • Takes effort to build and to maintain
  • Weak or flaky tests give false confidence or noise
  • A slow pipeline slows everyone down
  • The pipeline holds powerful credentials
  • Full automation needs strong monitoring and rollback

Trade-offs

ChoiceWe gainWe lose
Many checksMore mistakes caught before users see themA slower pipeline and more upkeep
Few checksVery quick feedbackMore bugs reach production
Continuous deliveryA human decides when to releaseA wait, and a manual step to forget
Continuous deploymentFastest path to usersRequires very trusted tests and fast rollback
Run all tests on each changeComplete safetyLong waits, so use test selection or parallel runs
Hosted CINo servers to runLess control, and cost per minute

10Common Problems and Mistakes

Common mistakes

  1. Flaky tests. People re-run until green and stop trusting the result.
  2. A slow pipeline. Developers batch big changes to avoid waiting, which defeats the point.
  3. Rebuilding per environment. The tested build and the shipped build are different.
  4. Secrets in the repo or the logs. A pipeline log is read by many people.
  5. Long-lived branches. Merges become huge, so integration is no longer continuous.
  6. Ignoring a red main branch. Everyone stops caring.
  7. Deploying with no way back. The pipeline ships quickly, but nobody can undo.

Things to watch

🎲Flaky tests
Track and fix or remove them. A test that lies is worse than no test.
⏱️Pipeline time
Watch it grow. Cache, parallelise and trim slow tests.
πŸ”‘Credentials
Prefer short-lived, narrowly scoped credentials over long-lived keys.
πŸ“¦Supply chain
A bad dependency or build tool can ship malware. Pin versions and scan.

11Real-World Examples

πŸ™GitHub Actions
Pipelines described in files inside the repository, triggered by pushes and pull requests.
🦊GitLab CI/CD
Built into the same platform as the code, with environments and review apps.
🀡Jenkins
A long-standing open-source automation server, often self-hosted, with many plugins.
☸️Argo CD and Flux
GitOps tools that make a Kubernetes cluster match what is in Git.
πŸ§ͺLarge web companies
Many deploy to production many times a day, using automated checks and gradual rollouts.
🏦Regulated industries
Pipelines add approvals, audit logs and compliance checks, often using continuous delivery with a manual gate.
πŸ“Note
Tools and features change quickly. Check the documentation of the tool you use before relying on a specific feature.
Mini case: a safe pipeline for a web service
πŸ”¨Build + unit testsone image
→↓promote
🎭Stagingintegration + smoke
→↓approve
🐀Canary5% then 100%
→↓healthy
πŸš€Production
Build Pre-prod Gradual Live
One artifact is built, then promoted. A canary protects the last step.

12Related Topics to Read Next

Deployment Strategies Overview→

The pipeline's last stage runs one of these strategies.

Rolling Deployments→

A common strategy for the deploy stage.

Canary Releases→

Ship to a small slice, then grow.

Rollbacks and Immutable Infrastructure→

What the pipeline does when a release goes bad.

Secrets Management→

Pipelines need credentials, and must keep them safe.

Alerts and Monitoring→

The numbers that tell the pipeline a release is healthy.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • βœ”CI: merge small changes often. Build and test each one automatically.
  • βœ”Delivery vs deployment: delivery waits for a person, deployment ships by itself.
  • βœ”Order: cheap and fast checks first, slow and costly checks later.
  • βœ”Build once: promote the same artifact through every environment.
  • βœ”Red build: stop the line and fix it first.
  • βœ”Tests: many unit, some integration, few end-to-end. Fix flaky tests.
  • βœ”Safety: scans, secrets handled safely, gradual rollout, automatic rollback.
  • βœ”One line: β€œEvery change goes down the same automatic line of checks, so shipping becomes boring.”
← Previous
Deployment Strategies Overview
Next β†’
Rolling Deployments