Hmm, the user wants a comprehensive zero-downtime deployment pipeline covering blue/green, canary, health checks, and rollback. This is a practical infrastructure question, likely from a DevOps engineer or tech lead implementing robust deployments.
The user didn't specify a tech stack, so I'll keep it generic but concrete with examples (like AWS/Google Cloud/Kubernetes). They probably need actionable steps, not just theory. The phrase "draft" suggests they want a template they can adapt.
Key points to cover: the pipeline stages (build, deploy, validate, rollback), how blue/green and canary fit together (they're often combined), health check design (application vs infrastructure level), and automated rollback triggers. Should emphasize safety—no human in the loop during critical steps.
Ah, and must warn about pitfalls: database migrations are the classic zero-downtime killer. Need to call that out explicitly. Also, traffic shifting strategies matter (instant vs gradual). The user might not realize canary is typically a phase within blue/green, not separate.
Let's structure it: high-level diagram first, then detailed stages with "why" explanations, then checklist. Avoid vendor lock-in but use cloud examples for clarity. Stress monitoring and observability—without metrics, canary is just guessing.
Wait, should I include feature flags? Not explicitly asked, but they're part of modern canary strategies. Maybe a footnote. Stick to the request though—blue/green, canary, health checks, rollback. Keep it tight.
Here’s a comprehensive zero-downtime deployment pipeline combining blue/green, canary, health checks, and automated rollback. This design is cloud-agnostic but uses common tooling examples (Kubernetes, AWS, etc.).
High-Level Architecture
[CI Build] → [Artifact Registry] → [Deployment Orchestrator]
↓
[Blue (Current) / Green (New)] + [Canary Pods/Instances]
↓
[Health Checks + Traffic Shifting] → [Monitoring/Alerts]
↓
[Full Cutover OR Rollback on Failure]
Pipeline Stages
1. Pre-Deployment (CI/CD Trigger)
- Trigger: Merge to
main branch, or manual approval.
- Actions:
- Run unit/integration tests.
- Build container image (Docker) or artifact.
- Push to immutable artifact registry (e.g., ECR, GCR, Docker Hub).
- Tag with
git SHA + semantic version (e.g., v1.2.3-rc.1).
- Do not deploy yet—artifact is ready.
2. Blue/Green Deployment Setup
- Blue: Current live environment (stable).
- Green: New environment (parallel, identical infra).
- Steps:
- Provision Green:
- Deploy new version to isolated green environment (new K8s namespace, new ASG, new ECS service, etc.).
- Use same config as blue (env vars, secrets via vault, scaling policies).
- No traffic routed to green yet.
- Database/State Considerations:
- Ensure schema changes are backward-compatible (expand-contract pattern).
- Use change data capture or dual-write if schema change is breaking.
- Never point green to blue’s database unless migration is safe.
3. Canary Deployment within Green
- Purpose: Test new version with real traffic, but limited.
- Implementation:
- Canary Duration: 5–30 mins, or until metrics stabilize.
4. Health Checks (Critical)
Define multi-layered checks:
| Layer | Check |
|---|
| Infrastructure | Pod/instance healthy (K8s liveness/readiness, EC2 status checks). |
| Application | /health endpoint (returns 200 only if DB/cache/deps are ready). |
| Business Logic | Smoke tests: /health/details?check=db, /health/details?check=payment. |
| Synthetic | External probe (e.g., Pingdom, New Relic Synthetics) hitting canary URL. |
Health Check Rules:
- Fail fast: If health check fails → immediate halt, no more traffic shift.
- Canary must pass all checks before traffic increase.
- Use SLI-based checks: error rate < 0.1%, latency p95 < 200ms, throughput stable.
5. Traffic Shifting & Monitoring
- Gradual Shift: Increase traffic to green in increments (e.g., 5% steps).
- Monitor During Shift:
- Error rates (4xx/5xx) – compare blue vs green.
- Latency (p50, p95, p99).
- Throughput (requests/sec).
- Business metrics (conversion, signups, etc.).
- Resource usage (CPU, memory, DB connections).
- Tools: Prometheus + Grafana, Datadog, New Relic, CloudWatch.
- Alert Thresholds:
- Error rate increase > 50% relative to baseline.
- Latency p95 > 2x baseline.
- Crash loops (K8s pod restarts).
6. Full Cutover (Blue → Green)
- If canary passes all checks for X minutes:
- Route 100% traffic to green.
- Keep blue running but idle for rollback window (e.g., 15–60 mins).
- Optional: Run integration/e2e tests against green under full load.
- Cutover Strategy:
- Atomic switch: Update load balancer/ingress to point to green (instant, <1 sec downtime if LB handles connections gracefully).
- Drain blue: Let existing connections finish (set LB connection draining to 60–300 sec).
7. Rollback (Automated & Manual)
- Automated Rollback Triggers (configure in deployment tool):
- Health check failure during canary.
- Error rate spike > threshold within 2 mins of traffic shift.
- Latency degradation > threshold.
- Canary pods crash-looping.
- Rollback Action:
- Immediately route 100% traffic back to blue.
- Terminate green environment (or scale to 0).
- Alert team with rollback reason + metrics snapshot.
- Manual Rollback:
- Button in CI/CD dashboard (e.g., Spinnaker, Argo CD, GitHub Actions).
- Rollback to previous stable artifact tag.
- Cooldown period: Prevent immediate re-deploy after rollback (e.g., 10 mins).
8. Post-Deployment
- Blue cleanup: After rollback window expires, deprovision blue (save cost).
- Update DNS/cnames if using external DNS (low TTL required, e.g., 60 sec).
- Run chaos tests on new version in isolated env (optional but recommended).
- Document: Deployment success/failure, metrics, rollbacks in changelog.
Tools & Implementation Examples
| Component | Example Tools |
|---|
| Orchestration | Spinnaker, Argo CD, AWS CodeDeploy, GitHub Actions (with environments) |
| Infrastructure | Kubernetes (namespaces), AWS (ASG + ALB target groups), Terraform |
| Traffic Shifting | Istio, Nginx ingress, AWS ALB weights, GCP Traffic Director |
| Health Checks | K8s probes, Consul health, intent-based routing (service mesh) |
| Monitoring | Prometheus + Alertmanager, Datadog, New Relic, CloudWatch |
| Rollback | Automated via CI/CD tool, or kubectl rollout undo, AWS CodeDeploy rollback |
Critical Considerations & Pitfalls
-
Database Migrations:
- Never break backward compatibility.
- Run migrations before traffic shift (against blue’s DB) if additive.
- For breaking changes: use dual writes, shadow tables, feature flags.
-
Stateful Services:
- Cache (Redis), queues (Kafka), object storage—must be shared or replicated between blue/green.
- Prefer externalized state (cloud-managed services).
-
Session Stickiness:
- Avoid sticky sessions unless absolutely necessary. Use distributed sessions (Redis) if needed.
- If sticky, drain sessions from blue before deprovision.
-
Configuration & Secrets:
- Use external config store (Consul, Vault, Parameter Store)—do not bake into image.
- Canary and green must have identical config except version.
-
Cost:
- Blue/green doubles infra during deployment. Use auto-scaling to scale green down if idle.
- Consider spot instances for green if non-critical.
-
DNS TTL:
- If using DNS-based routing, TTL must be ≤ 60 seconds for quick cutover/rollback.
Sample Pipeline as Code (GitHub Actions + K8s)
name: Zero-Downtime Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build & Push Image
run: |
docker build -t ${{ env.REGISTRY }}/app:${{ github.sha }} .
docker push ${{ env.REGISTRY }}/app:${{ github.sha }}
- name: Deploy to Green (K8s)
run: |
kubectl apply -f k8s/green-deployment.yaml --namespace=green
kubectl apply -f k8s/canary-ingress.yaml --namespace=green
- name: Run Canary Health Checks
run: |
./scripts/canary-checks.sh --namespace=green --duration=10m
- name: Increase Canary Traffic
run: |
kubectl patch ingress canary-ingress -n green --type='json' -p='[{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/service/name", "value":"app-green"}]'
- name: Full Cutover
if: success()
run: |
kubectl patch ingress main-ingress -n blue --type='json' -p='[{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/service/name", "value":"app-green"}]'
kubectl delete deployment app-blue -n blue
Final Checklist
This pipeline ensures zero downtime, fast rollback, and gradual risk exposure via canary. Adjust percentages, durations, and checks based on your risk tolerance and application criticality.