Continuous Delivery (CD) is a software engineering approach in which teams produce software in short cycles, ensuring that the software can be reliably released at any time.
It extends Continuous Integration (CI) by automatically deploying all code changes to a testing, staging, or production environment after the build stage.
Standardizing how code is deployed in production minimizes downtime and limits blast radius in case of failures.
1. Rolling Update (Incremental)
Replaces instances of the old version with the new version gradually. E.g., updating 1 of 5 servers at a time.
Pros: Zero downtime, easy to set up.
Cons: High duration; for a period, both versions run concurrently, requiring backwards-compatible APIs.
2. Blue-Green Deployment (Red-Black)
Two identical production environments exist: “Blue” (active) and “Green” (idle). The new version is deployed to Green, tested, and traffic router switches to Green.
Pros: Instant swap, zero downtime, instant rollbacks (switch router back to Blue).
Cons: Doubles infrastructure costs, data sync challenges between databases during switch.
3. Canary Deployment
Deploys the new version to a tiny subset of production servers (e.g., 2% of traffic). If no errors occur, traffic is gradually increased.
Pros: Minimal blast radius, tests code with real production traffic.
Cons: Complex routing setup, slow rollout times.
GitOps & Infrastructure as Code (IaC)
CD for modern cloud systems leverages IaC and GitOps to maintain consistent state.
Infrastructure as Code (IaC)
Managing and provisioning infrastructure through machine-readable definition files (e.g., Terraform, Ansible, CloudFormation) rather than manual configuration.
Ensures that staging and production environments are identical replicas, eliminating environment drift.
GitOps (Git as Source of Truth)
A paradigm for Kubernetes and cloud-native applications where Git repositories hold declarative descriptions of infrastructure.
Pull-based CD (e.g., ArgoCD, Flux): Agents inside the cluster constantly compare the Git repo state with the running cluster state. If they differ, the agent pulls changes and updates the cluster to match Git (Self-healing).
CD Configuration Examples
GitHub Actions Deployment Pipeline
.github/workflows/cd.yml
name: Continuous Deliveryon: workflow_run: workflows: ["Continuous Integration"] types: [completed] branches: [main]jobs: deploy-staging: if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest steps: - name: Deploy to Staging Environment run: | echo "Deploying build artifact to staging server..." # Command to push image or copy files: # ssh deploy@staging-server "docker-compose pull && docker-compose up -d" deploy-production: needs: deploy-staging runs-on: ubuntu-latest environment: name: production url: https://myapp.com steps: - name: Deploy to Production (Manual Approval Gate Required) run: | echo "Deploying verified build to production cluster..." # E.g., updating helm chart or trigger webhook: # helm upgrade --install my-app ./charts/my-app