Implementing Deployment Patterns
1. Understanding Blue-Green Deployment
┌──────── Blue (live) ────────┐
LB ──────►│ v1.0 v1.0 v1.0 │
└──────────────────────────────┘
┌──────── Green (staged) ──────┐
│ v2.0 v2.0 v2.0 │ ◄── smoke tests
└──────────────────────────────┘
↓ flip LB
┌──────── Green (live) ────────┐
LB ──────►│ v2.0 v2.0 v2.0 │| Property | Detail |
|---|---|
| Pro | Instant rollback (flip back) |
| Con | 2× capacity briefly; DB schema must support both |
2. Implementing Canary Releases
| Step | Traffic % |
|---|---|
| 1 | 1% → check error/latency SLO |
| 2 | 5% → 10 min |
| 3 | 25% → 30 min |
| 4 | 50% → 1 h |
| 5 | 100% |
| Tools | Argo Rollouts, Flagger, Spinnaker |
| Auto-rollback | Triggered by Prometheus analysis |
3. Implementing Rolling Updates
Example: K8s Deployment strategy
spec:
replicas: 10
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 2
minReadySeconds: 15
template:
spec:
containers:
- name: api
readinessProbe: { httpGet: { path: /ready, port: 8080 } }
4. Implementing Feature Flags
| Use | Detail |
|---|---|
| Decouple deploy from release | Ship dark, enable later |
| Targeting | Per user, region, tenant |
| Kill switch | Disable misbehaving feature instantly |
| Cleanup | Remove flag after rollout to avoid debt |
5. Implementing A/B Testing
| Step | Detail |
|---|---|
| Hypothesis | Variant B improves metric M by Δ |
| Assignment | Hash(user_id) % 100; sticky |
| Sample size | Power analysis (e.g., 80% power) |
| Analysis | Significance test (z-test, CUPED) |
| Tools | Optimizely, GrowthBook, LaunchDarkly Experiments |
6. Implementing Shadow Traffic
| Property | Detail |
|---|---|
| Definition | Mirror prod traffic to new version; discard response |
| Validates | Performance, correctness vs baseline |
| Watch | Idempotency of writes; sandbox external calls |
7. Understanding Immutable Infrastructure
| Principle | Detail |
|---|---|
| Never patch in place | Replace, don't mutate |
| Image-based | Container or AMI as deploy unit |
| Tools | Packer, container images, Kubernetes |
| Benefits | Repeatability, easy rollback, no config drift |
8. Implementing Zero-Downtime Deployments
| Requirement | Detail |
|---|---|
| Graceful shutdown | SIGTERM → drain → close in terminationGracePeriodSeconds |
| Readiness probe | Don't accept traffic until ready |
| PreStop hook | Wait + flush in-flight |
| Backward-compatible schema | Old + new code coexist |
| PDB | PodDisruptionBudget for K8s |
9. Implementing Database Migration Strategies
| Pattern | Detail |
|---|---|
| Expand / contract | Add column → backfill → switch reads → drop old |
| Online schema change | gh-ost, pt-online-schema-change |
| Versioned migrations | Flyway, Liquibase, Alembic |
| Decouple deploy | App tolerates both schemas during rollout |
10. Implementing Rollback Mechanisms
| Mechanism | Detail |
|---|---|
| kubectl rollout undo | Previous ReplicaSet |
| Argo Rollouts abort | Auto-revert canary |
| Image pin | Roll forward by tag |
| DB | Backward-compatible migrations enable rollback w/o data revert |
| Feature flag off | Instant code-path rollback |