π What is CI/CD?
CI/CD stands for Continuous Integration / Continuous Delivery (or Deployment) - a set of practices that automate the software delivery process.
Benefits of CI/CD
β‘ Speed
Deploy in minutes instead of days. Faster feedback on code changes. Reduce time to market.
π‘οΈ Quality
Catch bugs early (before production). Consistent testing on every change. Reduce human error.
π Consistency
Same process every time. Reproducible builds. No "works on my machine" issues.
π Visibility
See build/test status at a glance. Track deployment history. Easy rollbacks.
π§ Continuous Integration (CI)
Automatically build and test code every time someone pushes changes.
Developer A βββ
β βββββββββββββββββββββββββββββββββββββββ
Developer B βββΌβββββΆβ Shared Repository (main branch) β
β βββββββββββββββββββββββββββββββββββββββ
Developer C βββ β
βΌ
βββββββββββββββββββββββ
β CI Server β
β (GitHub Actions) β
βββββββββββββββββββββββ
β
ββββββββββββββββββΌβββββββββββββββββ
βΌ βΌ βΌ
βββββββββββ βββββββββββββ βββββββββββββ
β Build β β Test β β Lint β
βββββββββββ βββββββββββββ βββββββββββββ
β
βΌ
β
Pass / β Fail
CI Key Practices
| Practice | Description |
|---|---|
| Frequent commits | Integrate small changes often (daily or more) |
| Automated builds | Every push triggers a build |
| Automated tests | Unit, integration tests run automatically |
| Fast feedback | Know within minutes if something broke |
| Fix immediately | Broken build = top priority to fix |
π Continuous Delivery vs Deployment
There are TWO meanings of "CD":
π¦ Continuous Delivery
Code is ALWAYS ready to deploy, but human MANUALLY approves and triggers production deploy.
Build β Test β Staging β [π€ Approval] β Production
β
Manual click
π€ Continuous Deployment
Every change that passes tests goes to production AUTOMATICALLY. No human intervention needed.
Build β Test β Staging β Production
β β
βββββββββββββ
Automatic!
Comparison
| Aspect | Continuous Delivery | Continuous Deployment |
|---|---|---|
| Production deploy | Manual trigger | Automatic |
| Human approval | Required | Not required |
| Risk | Lower (human review) | Higher (need great tests) |
| Speed | Fast | Fastest |
| Best for | Regulated industries, banks | SaaS, web apps |
π¦ Pipeline Stages
A typical CI/CD pipeline has these stages:
1οΈβ£ Source
- Code pushed to repository
- Pull request opened
- Triggers the pipeline
2οΈβ£ Build
- Compile code
- Install dependencies
- Create build artifacts
- Run linters
3οΈβ£ Test
- Unit tests
- Integration tests
- E2E tests
- Security scans
4οΈβ£ Deploy
- Deploy to staging
- Run smoke tests
- Deploy to production
- Monitor for issues
π οΈ Popular CI/CD Tools
Cloud-Based (Hosted)
| Tool | Description |
|---|---|
| GitHub Actions | Built into GitHub, YAML config |
| GitLab CI/CD | Built into GitLab, .gitlab-ci.yml |
| CircleCI | Fast, Docker-first |
| Azure DevOps | Microsoft ecosystem |
Self-Hosted
| Tool | Description |
|---|---|
| Jenkins | Most flexible, plugin ecosystem |
| TeamCity | JetBrains, great for Java |
| Bamboo | Atlassian, integrates with Jira |
GitHub Actions Example
# .github/workflows/ci.yml
name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Test
run: npm test
- name: Build
run: npm run build
π― Deployment Strategies
Modern deployment is about controlling traffic flow across multiple servers, not just replacing files.
Rolling Deployment
Update servers one by one while keeping the service running.
- β Zero downtime
- β Low infrastructure cost
- β Slow rollback
Blue-Green
Maintain two complete environments. Switch traffic instantly.
- β Instant rollback
- β Full testing before switch
- β 2x infrastructure cost
Canary
Send small % of traffic to new version first. Gradually increase.
- β Test with real traffic
- β Gradual rollout
- β More complex
Feature Flags
Deploy code, hide behind flags. Toggle at runtime.
- β Instant enable/disable
- β No deployment to toggle
- β Code complexity
Rolling Deployment
STEP 1: All servers on v1.0 ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β v1.0 β β β v1.0 β β β v1.0 β β β v1.0 β β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ STEP 2: Update Server 1 (others still serving) ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β UPDATING β β v1.0 β β β v1.0 β β β v1.0 β β β β v2.0 β β serving β β serving β β serving β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ STEP 3-4: Continue until all updated ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β v2.0 β β β v2.0 β β β v2.0 β β β v2.0 β β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ
Blue-Green Deployment
USERS
β
βΌ
βββββββββββββββββ
β Load Balancer β
β (Switch) β
βββββββββββββββββ
β
ββββββββββββββ΄βββββββββββββ
βΌ βΌ
βββββββββββββββββββββββ βββββββββββββββββββββββ
β BLUE ENVIRONMENT β β GREEN ENVIRONMENT β
β (v1.0) β β (v2.0) β
β β β β
β [LIVE] ββββββββββ β [STANDBY] β
βββββββββββββββββββββββ βββββββββββββββββββββββ
SWITCH: Change load balancer config
Blue becomes standby, Green becomes live
INSTANT rollback: just switch back!
Canary Deployment
USERS (100%)
β
βΌ
βββββββββββββββββ
β Load Balancer β
β (% routing) β
βββββββββββββββββ
β
ββββββββββββββ΄βββββββββββββ
β β
95% traffic 5% traffic
βΌ βΌ
βββββββββββββββββββββββ βββββββββββββββββββββββ
β STABLE (v1.0) β β CANARY (v2.0) β
β 8 servers β β 1 server β
βββββββββββββββββββββββ βββββββββββββββββββββββ
GRADUAL ROLLOUT:
Step 1: 5% β Test with small % of real users
Step 2: 25% β Looking good...
Step 3: 50% β Half and half
Step 4: 100% β Full rollout!
π© Feature Flags
Deploy the same code to all servers, but hide new features behind runtime flags stored externally.
YOUR APP (deployed code) FLAG SERVICE (external)
βββββββββββββββββββββββββ βββββββββββββββββββββββββ
βββββββββββββββββββββββ βββββββββββββββββββββββ
β β HTTP β β
β if (flags.newUI) β ββββββββΊ β Flag Dashboard β
β <NewUI /> β fetch β βββββββββββββββββ β
β else β β β newUI: true β β
β <OldUI /> β β β darkMode: 50% β β
β β β β betaAPI: off β β
βββββββββββββββββββββββ β βββββββββββββββββ β
β β
Same deployed code! β Changed via UI β
No redeployment needed! β (no deploy!) β
βββββββββββββββββββββββ
How It Works
1οΈβ£ App Startup
App fetches all flag values from Flag Service. Caches them locally.
2οΈβ£ Runtime Check
Code checks flag value from cache. Shows feature based on flag.
3οΈβ£ Real-time Updates
WebSocket or polling for updates. Flag changed? App updates immediately!
4οΈβ£ Toggle via Dashboard
Product manager toggles flag in UI. NO deployment needed!
Code Example
// Initialize flag service (external)
const flags = new FlagService({
apiUrl: 'https://flags.mycompany.com/api',
apiKey: 'your-api-key',
});
await flags.initialize();
// Use in component
function CheckoutPage() {
// Value comes from EXTERNAL service, not code
const showNewCheckout = flags.isEnabled('new-checkout');
if (showNewCheckout) {
return <NewCheckout />;
}
return <OldCheckout />;
}
Popular Feature Flag Services
| Service | Description |
|---|---|
| LaunchDarkly | Industry leader, enterprise |
| Split.io | Experimentation focused |
| Flagsmith | Open source option |
| ConfigCat | Simple, affordable |
| Unleash | Open source, self-host |
π Choosing the Right Strategy
| Aspect | Rolling | Blue-Green | Canary | Feature Flags |
|---|---|---|---|---|
| Rollback Speed | Slow | Instant β | Fast | Instant β |
| Infrastructure Cost | Low β | High (2x) | Medium | Low β |
| Complexity | Low β | Medium | High | Medium |
| Real User Testing | Yes | No | Yes β | Yes β |
When to Use What
π Rolling
Best for: Simple apps, internal tools, cost-conscious, stateless services
Avoid: Breaking changes, need instant rollback
π΅π’ Blue-Green
Best for: Critical systems, instant rollback needs, compliance
Avoid: Very large infra, frequent deploys
π€ Canary
Best for: Large user base, real traffic testing, gradual rollout
Avoid: Small user base, simple internal tools
π© Feature Flags
Best for: A/B testing, trunk-based dev, beta programs
Avoid: Simple features, short-lived changes
Who Uses What
| Company | Strategy | Notes |
|---|---|---|
| Netflix | Canary + Feature Flags | Automated canary analysis |
| Feature Flags (Gatekeeper) | Everything behind flags | |
| Amazon | Canary + One-box | Deploy to ONE server first |
| Canary + Feature Flags | Multiple canarying levels | |
| Banks | Blue-Green | Guaranteed rollback |
β Best Practices
β‘ Pipeline
- Keep builds fast (< 10 min)
- Run tests in parallel
- Fail fast (quick checks first)
- Use caching
- Environment parity
π Deployment
- Automate everything
- Monitor deployments
- Easy rollbacks (one click)
- Security scanning
- Notify on failure
π© Feature Flags
- Clean up old flags
- Use naming conventions
- Document flags
- Set expiration dates
- Test both states
π Summary
| Component | Description |
|---|---|
| CI | Merge frequently, automated build & test |
| CD (Delivery) | Always deployable, manual production trigger |
| CD (Deployment) | Fully automated to production |
| Rolling | Update servers one by one |
| Blue-Green | Two environments, instant switch |
| Canary | Gradual % rollout |
| Feature Flags | Runtime toggle, no deploy needed |