Skip to main content

CI/CD Pipeline Architecture: Stages, Gates & Deployment Strategies

A well-designed CI/CD pipeline is the difference between deploying with confidence and deploying with dread. This guide covers how to structure pipeline stages, what quality gates to enforce, which deployment strategy fits your reliability requirements, and how GitOps changes the deployment model entirely — with architecture diagrams in code you can adapt immediately.

✓ 6-stage pipeline architecture ✓ Quality gate enforcement ✓ Blue-green / canary / rolling deploy ✓ Trunk-based vs GitFlow comparison ✓ GitOps pattern with ArgoCD
Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →

Complete 6-Stage Pipeline

A production-grade GitHub Actions pipeline with all six stages: source, build, test, security scan, deploy to staging, and deploy to production with manual approval gate.

name: Production Pipeline

on:
  push:
    branches: [main]

jobs:
  # Stage 1: Source — handled by checkout in each job

  # Stage 2 + 3: Build & Test (parallel)
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - uses: actions/upload-artifact@v4
        with: { name: dist, path: dist/ }

  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm test -- --coverage
      - name: Quality Gate — coverage must be ≥80%
        run: |
          COVERAGE=$(cat coverage/coverage-summary.json | jq '.total.lines.pct')
          if (( $(echo "$COVERAGE < 80" | bc -l) )); then
            echo "Coverage $COVERAGE% is below 80% threshold"; exit 1
          fi

  # Stage 4: Security
  security:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm audit --audit-level=high
      - uses: github/codeql-action/analyze@v3

  # Stage 5: Deploy to Staging (auto)
  deploy-staging:
    needs: [build, test, security]
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - uses: actions/download-artifact@v4
        with: { name: dist }
      - run: ./scripts/deploy.sh staging

  # Stage 6: Deploy to Production (manual approval)
  deploy-production:
    needs: deploy-staging
    runs-on: ubuntu-latest
    environment:
      name: production
      url: https://example.com
    steps:
      - uses: actions/download-artifact@v4
        with: { name: dist }
      - run: ./scripts/deploy.sh production

Deployment Strategies Compared

The right deployment strategy depends on your tolerance for downtime, infrastructure budget, and traffic volume. Here is a concise comparison of the three main approaches.

# Blue-Green: two environments, instant traffic switch
# Infrastructure: 2x cost
# Rollback time: seconds (flip load balancer)
resource "aws_lb_listener_rule" "blue_green_switch" {
  action {
    type             = "forward"
    target_group_arn = var.active_env == "blue" ? aws_lb_target_group.blue.arn : aws_lb_target_group.green.arn
  }
}

# Canary: route % of traffic to new version
# Tools: AWS CodeDeploy, Argo Rollouts, Istio, nginx split_clients
# Monitor for 15min at 5%, then ramp to 50%, then 100%

# Rolling: replace instances gradually
# Kubernetes rolling update (default strategy)
strategy:
  type: RollingUpdate
  rollingUpdate:
    maxSurge: 1         # add 1 new pod before removing old
    maxUnavailable: 0   # never reduce below desired count

GitOps with ArgoCD

In a GitOps pipeline, CI handles build and image push. Deployment is driven by a separate manifest repository watched by ArgoCD — any change to the manifests is automatically applied to the cluster.

# CI pipeline: build image and update manifest repo
- name: Build and push image
  run: |
    docker build -t myorg/app:$GITHUB_SHA .
    docker push myorg/app:$GITHUB_SHA

- name: Update manifest repository
  run: |
    git clone https://x-token:${{ secrets.MANIFEST_TOKEN }}@github.com/myorg/k8s-manifests.git
    cd k8s-manifests
    # Update image tag in Helm values
    yq e '.image.tag = "${{ github.sha }}"' -i apps/myapp/values.yaml
    git commit -am "chore: update myapp to ${{ github.sha }}"
    git push

# ArgoCD Application manifest (in k8s-manifests repo)
# argocd-app.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: myapp
spec:
  source:
    repoURL: https://github.com/myorg/k8s-manifests
    path: apps/myapp
    targetRevision: main
  destination:
    server: https://kubernetes.default.svc
    namespace: production
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

Deployment Strategy Decision Matrix

Strategy Downtime Rollback speed Infra cost Best for
Blue-Green Zero Seconds 2x Critical services, regulated environments
Canary Zero Minutes ~1.1x High-traffic, risk-sensitive releases
Rolling Zero (if configured) Minutes ~1x Most Kubernetes workloads (default)
Recreate Brief downtime Minutes 1x Dev/staging, non-critical services

Frequently Asked Questions

What are the essential stages in a CI/CD pipeline?▼

A complete CI/CD pipeline typically has six stages: (1) Source — code checkout, branch policies. (2) Build — compile, bundle, create artifacts. (3) Test — unit tests, integration tests, code coverage. (4) Security — SAST, dependency scanning, secret detection. (5) Deploy — push artifact to environment (staging, production). (6) Monitor — health checks, rollback triggers, observability. Not every pipeline needs all six; a small internal tool might skip security scanning. Start with Source→Test→Deploy and add stages as the project matures.

What is a quality gate and what should mine check?▼

A quality gate is a pass/fail checkpoint that blocks pipeline progression if minimum standards are not met. Typical gates: test coverage must be ≥80%, no HIGH or CRITICAL severity vulnerabilities, lint must pass with zero errors, build size must not exceed threshold. In SonarQube, quality gates are configured per project. In GitHub Actions, a status check on the branch protection rule acts as a quality gate — PRs cannot merge unless it passes.

Blue-green vs canary vs rolling deployment — when to use each?▼

Blue-green: run two identical production environments, switch traffic instantly by flipping DNS or load balancer. Zero-downtime, instant rollback. Costs double the infrastructure. Best for: critical services where any downtime is unacceptable. Canary: route a small % of traffic (1-5%) to the new version, monitor error rates and latency, gradually increase to 100% if metrics are healthy. Best for: high-traffic services where you want real production signal before full rollout. Rolling: gradually replace old instances with new ones, a few at a time. Lower cost than blue-green, slower rollback. Best for: services with multiple instances where infrastructure cost is a concern.

What is GitOps and how does it relate to CI/CD pipelines?▼

GitOps is a deployment pattern where the desired state of your infrastructure and applications is stored in Git, and automated agents continuously reconcile the live environment to match. In a GitOps model, your CI pipeline builds and pushes a container image, then updates a manifest repository (Helm chart or Kubernetes YAML) with the new image tag. A GitOps agent (ArgoCD, Flux) watches the manifest repository and applies changes to the cluster automatically. The key benefit: Git becomes your audit trail — every change is a commit, and rollback is a git revert.

Trunk-based development vs GitFlow — which branching strategy is better for CI/CD?▼

Trunk-based development (TBD) is better for CI/CD velocity. All developers commit to a single main branch (or short-lived feature branches that merge within hours). This keeps the pipeline simple: main is always deployable, CI runs on every commit, and there are no long-lived branches to merge and conflict. GitFlow uses long-lived develop, release, and hotfix branches. It was designed for scheduled release cycles and adds significant merge complexity. Unless you maintain multiple versions in production simultaneously, trunk-based development with feature flags is the modern best practice.

What is pipeline-as-code and why does it matter?▼

Pipeline-as-code means your CI/CD configuration lives in version-controlled files (Jenkinsfile, .github/workflows/, .gitlab-ci.yml) alongside application code. This means pipeline changes go through the same review process as code changes — PRs, code review, and rollback via git. It also enables testing pipeline changes in feature branches before merging. The alternative — configuring pipelines through UI click-ops — is fragile, unauditable, and impossible to reproduce. Pipeline-as-code is a non-negotiable best practice for any team beyond one person.