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          │
PropertyDetail
ProInstant rollback (flip back)
Con2× capacity briefly; DB schema must support both

2. Implementing Canary Releases

StepTraffic %
11% → check error/latency SLO
25% → 10 min
325% → 30 min
450% → 1 h
5100%
ToolsArgo Rollouts, Flagger, Spinnaker
Auto-rollbackTriggered 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

UseDetail
Decouple deploy from releaseShip dark, enable later
TargetingPer user, region, tenant
Kill switchDisable misbehaving feature instantly
CleanupRemove flag after rollout to avoid debt

5. Implementing A/B Testing

StepDetail
HypothesisVariant B improves metric M by Δ
AssignmentHash(user_id) % 100; sticky
Sample sizePower analysis (e.g., 80% power)
AnalysisSignificance test (z-test, CUPED)
ToolsOptimizely, GrowthBook, LaunchDarkly Experiments

6. Implementing Shadow Traffic

PropertyDetail
DefinitionMirror prod traffic to new version; discard response
ValidatesPerformance, correctness vs baseline
WatchIdempotency of writes; sandbox external calls

7. Understanding Immutable Infrastructure

PrincipleDetail
Never patch in placeReplace, don't mutate
Image-basedContainer or AMI as deploy unit
ToolsPacker, container images, Kubernetes
BenefitsRepeatability, easy rollback, no config drift

8. Implementing Zero-Downtime Deployments

RequirementDetail
Graceful shutdownSIGTERM → drain → close in terminationGracePeriodSeconds
Readiness probeDon't accept traffic until ready
PreStop hookWait + flush in-flight
Backward-compatible schemaOld + new code coexist
PDBPodDisruptionBudget for K8s

9. Implementing Database Migration Strategies

PatternDetail
Expand / contractAdd column → backfill → switch reads → drop old
Online schema changegh-ost, pt-online-schema-change
Versioned migrationsFlyway, Liquibase, Alembic
Decouple deployApp tolerates both schemas during rollout

10. Implementing Rollback Mechanisms

MechanismDetail
kubectl rollout undoPrevious ReplicaSet
Argo Rollouts abortAuto-revert canary
Image pinRoll forward by tag
DBBackward-compatible migrations enable rollback w/o data revert
Feature flag offInstant code-path rollback