Continuous Delivery & Deployment
CI/CD

Continuous Delivery & Deployment

Master Continuous Delivery (CD): automated release packaging, staging environment validation, approval gates, and zero-downtime deployment.

In the early days of software, releasing a new version was often a stressful, weekend-long ordeal. Teams scheduled maintenance windows where servers were taken down for hours. An engineer worked through a long checklist, copying files manually, running database scripts, and updating configuration files on live servers. Inevitably, late at night, something went wrong. A setting was missing or a database change failed to apply. The team spent hours troubleshooting, and sometimes had to roll back the entire release in exhaustion by Monday morning. Continuous Delivery was created to make software deployments routine and predictable. It ensures that software is always in a release-ready state, and that deploying to any environment (from a test server to production) uses the exact same automated, dependable pipeline.

Definition

Continuous Delivery is a software engineering approach where teams produce software in short cycles, ensuring that code can be reliably released to production at any time through automated packaging, environment setup, and testing, with the final release triggered on demand.

Why It Matters

When deployments are rare and manual, they carry high risk. Because they carry high risk, teams delay them. Because teams delay them, each release contains hundreds of changes. And because releases are huge, they frequently fail. Continuous Delivery breaks this cycle by making releases small, automated, and routine. Deploying daily or weekly removes deployment anxiety, reduces business risk, and gets new features into users' hands much faster.

How It Works

Continuous Delivery functions as an automated promotion pipeline built on several core ideas: 1. Immutable Artifact Promotion: An application is built and packaged once (such as a Docker container image) during the CI stage. That exact same image is then promoted sequentially through Development, Staging, and Production. Differences like database passwords or hostnames are supplied at runtime via environment variables or secret managers. 2. Staging Environment Parity: The staging environment should closely match production in operating system, database versions, and network structure. Automated integration and smoke tests run in staging to catch environmental issues before production. 3. Continuous Delivery vs Continuous Deployment: • Continuous Delivery: The pipeline automates building, testing, and deploying to staging. The application is ready to deploy to production at any time, but requires an explicit approval step or button click. • Continuous Deployment: There is no manual approval gate. Every commit that passes the automated pipeline deploys straight into live production within minutes. 4. Zero-Downtime Deployment Patterns: Modern pipelines use strategies like Blue-Green, Canary, or Rolling updates behind load balancers so that new application instances take over traffic smoothly without disconnecting users.

The Continuous Delivery Environment Promotion Flow

1. CI Verification
Unit tests pass and the pipeline builds an immutable container image tagged with the commit SHA
2. Registry Upload
The container image is published to a secure artifact registry (like ECR or GitHub Packages)
3. Development Deploy
The image is deployed to an internal developer environment for initial verification
4. Staging Deploy
The image is deployed to a production-like staging environment
5. Smoke & Integration Tests
Automated tests verify that APIs and database interactions work properly in staging
6. Production Gate
Continuous Delivery pauses for team approval; Continuous Deployment deploys automatically
7. Canary Rollout
A small percentage of production traffic (such as 5%) routes to the new version to check error rates
8. Complete Promotion
Once verified healthy, the new version handles 100% of traffic and the old version is retired

Key Points

  • Software should stay in a deployable state throughout its development.
  • Build once, deploy everywhere: do not recompile an application for different target environments.
  • Continuous Delivery uses a human approval step before production; Continuous Deployment is completely automated.
  • Database changes must be backward-compatible to allow zero-downtime rolling updates.
  • Automated rollbacks ensure that if health checks fail, the system restores the previous version without human intervention.

Steps

  1. Package Applications in Containers

    Use Docker to package your application and its dependencies into a consistent container image that runs identically everywhere.

  2. Keep Configuration Outside the Code

    Follow 12-Factor App principles by supplying environment variables and secrets at runtime so the same container image runs in all environments.

  3. Automate Staging Deployments

    Set your pipeline to deploy passing builds to a staging environment automatically, followed by automated smoke tests.

  4. Use Backward-Compatible Database Migrations

    Apply the Expand/Contract pattern for database changes so older and newer application versions can run alongside each other during updates.

  5. Set Up Automatic Rollback Triggers

    Define health checks so that if a new release experiences elevated error rates, traffic immediately reverts to the previous stable release.

Examples

The Train Schedule Analogy

Traditional deployments are like chartering a tour bus: you spend weeks organizing passengers and luggage, and if one person is late, the entire trip is delayed. Continuous Delivery is like a metro train arriving every three minutes: if a feature misses one train, it simply catches the next one without holding up anyone else.

Real-World Examples

Automated Canary Deployments at Scale

Large cloud platforms deploy microservice updates continuously using automated canary analysis. A new software version receives a tiny slice of live user traffic while monitoring tools compare latency, error rates, and CPU usage against the existing version. If metrics remain healthy, the new version gradually expands to 100% of traffic.

Technical Examples

Staging and Production Delivery Pipeline in GitHub Actionsyaml
name: Continuous Delivery Release Pipeline

on:
  push:
    branches: [main]

jobs:
  # 1. DEPLOY TO STAGING
  deploy-staging:
    name: Deploy to Staging
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - name: Check out code
        uses: actions/checkout@v4

      - name: Deploy image to staging cluster
        run: |
          echo "Deploying ghcr.io/myorg/api:${{ github.sha }} to Staging..."
          # kubectl apply -f k8s/staging/

      - name: Run automated health and smoke tests
        run: |
          echo "Checking staging health endpoint..."
          curl --fail --retry 5 https://staging-api.example.com/healthz

  # 2. DEPLOY TO PRODUCTION (Protected Environment)
  deploy-production:
    name: Deploy to Production
    needs: deploy-staging
    runs-on: ubuntu-latest
    environment:
      name: production # Requires designated team review in GitHub settings
    steps:
      - name: Check out code
        uses: actions/checkout@v4

      - name: Roll out update to production
        run: |
          echo "Deploying ghcr.io/myorg/api:${{ github.sha }} to Production..."
          # kubectl set image deployment/api api=ghcr.io/myorg/api:${{ github.sha }} -n prod
          # kubectl rollout status deployment/api -n prod --timeout=120s
This workflow models a Continuous Delivery setup: code merged to main automatically deploys to Staging, runs health checks, and pauses at the production environment until an authorized reviewer approves the deployment.

Continuous Delivery vs Continuous Deployment

AspectContinuous DeliveryContinuous Deployment
Release to ProductionTriggered manually when business team decidesTriggered automatically when all tests pass
Approval GateHuman clicks an approval button in the UIAutomated canary evaluation and health metrics
Risk ManagementCoordinated around business schedulesManaged through automated traffic percentages and quick rollbacks
Regulatory FitWell-suited for strict compliance rules (finance, healthcare)Well-suited for consumer web apps, SaaS, and public APIs
Testing RequirementHigh automated test coverageExtensive automated tests with complete confidence in test results

Progressive Delivery & Managing Blast Radius

1. Promotion Flow: Code is merged into the main branch. The resulting container artifact moves through development, staging, and production rather than managing separate code branches for each environment. 2. Progressive Delivery: When releasing updates to users, roll out gradually: • Step 1 (Internal): Route employee traffic to the new version. • Step 2 (Canary 5%): Route a small portion of user traffic to monitor performance and error rates. • Step 3 (Expansion): Gradually increase traffic to 25%, 50%, and then 100% as confidence builds. 3. Automatic Circuit Breakers: If error rates exceed safe thresholds during a canary phase, the pipeline automatically routes traffic back to the previous stable version.

Advantages

  • Low Deployment Stress: Automated, repeatable scripts replace risky manual checklists.
  • Faster Delivery: New features and bug fixes reach users in hours or days instead of months.
  • Zero Downtime: Rolling and blue-green updates eliminate user-facing maintenance windows.
  • Manageable Changes: Smaller updates mean smaller risks and straightforward rollbacks.

Limitations

  • Requires Database Care: Database schemas must be updated using non-breaking, backward-compatible steps.
  • Staging Maintenance: Keeping staging environments closely matched with production requires regular attention.

Interview Questions

How do you perform zero-downtime deployments when a database schema change is needed?

Zero-downtime database changes use the Expand and Contract pattern across separate releases: 1. Expand: Add the new column or table while leaving old fields intact so running code continues working. 2. Dual Write: Deploy code that writes to both old and new columns. 3. Backfill: Run a background job to copy older records to the new column. 4. Read New: Update the application to read from the new column. 5. Contract: Once the old column is no longer used anywhere, remove it in a final cleanup migration.

Practice Questions

  1. Walk through how you would rename a database column from 'phone' to 'mobile_number' without taking down the website.