1) Topology: blue-green with canary inside the cutover
- Blue = current production stack (stable).
- Green = new release stack (candidate), provisioned in parallel with identical capacity/infra config.
- Canary = controlled, progressive routing of a portion of production traffic to Green while Blue continues serving the rest.
This gives:
- Fast rollback (flip traffic back to Blue)
- Risk reduction (canary gates before full cutover)
- Operational parity (Green is a full prod-like stack, not a special canary-only deployment)
2) Traffic shifting design (routing + progression)
2.1 Routing mechanisms (choose one primary, one fallback)
Primary (recommended): L7 weighted routing
- Service mesh (Istio/Linkerd), ingress controller (NGINX/Envoy), or cloud LB (ALB/Traffic Director).
- Supports:
- Weighted splits (e.g., 99/1 → 95/5 → … → 0/100)
- Header/cookie overrides (route QA/internal users to Green)
- Sticky sessions (if required)
Fallback: DNS weighted routing
- Slower rollback due to TTL and caching; use only if L7 isn’t available.
2.2 Progressive schedule (example)
Use step-based progression with analysis windows:
- 0% (pre-traffic): Green up, passes smoke tests.
- 1% for 10–15 min
- 5% for 15–30 min
- 25% for 30–60 min
- 50% for 30–60 min
- 100% (full cutover) + bake period (e.g., 2–24h depending on risk)
Progression should be automatic but pausable (e.g., on-call can hold at 25%).
2.3 Guardrails
- Concurrency caps on Green (prevent overload during warm-up).
- Outlier detection / circuit breaking (if error rate spikes, shed canary traffic first).
- Session strategy
- Prefer stateless services.
- If stateful sessions exist: store in shared Redis/DB and ensure cookie/session compatibility across versions.
3) Health checks (pre-traffic, in-traffic, and dependency-aware)
3.1 App instance probes
- Liveness: “process should be restarted if stuck”
- Readiness: “instance can receive traffic”
- Include dependency checks carefully:
- Hard-fail readiness only on critical dependencies.
- For optional dependencies, degrade gracefully and emit signals.
3.2 Endpoint-level checks
- Smoke tests (pre-traffic): minimal critical flows (login, read, write, payment stub).
- Synthetic checks (continuous):
- Run against Blue and Green separately (distinct endpoints or routing header).
- Include multi-step transactions and auth.
3.3 Release-specific checks
- Config/secret validation (correct keys, feature flags, connectivity)
- Schema compatibility check (app can run against current DB schema before any cutover)
4) State migration strategy (zero-downtime + rollback-safe)
4.1 Use “expand → migrate → contract” (backward/forward compatible)
Goal: Blue and Green must both work during the whole canary.
- Expand (safe schema change)
- Add new tables/columns/indexes without removing or renaming old ones.
- Avoid “NOT NULL without default” on large tables; use phased constraints.
- Deploy Green
- Green reads/writes in a backward-compatible way.
- Prefer feature flags to enable new behavior gradually.
- Migrate data
- Backfill asynchronously (job/worker), idempotent, resumable.
- Monitor progress and lag.
- Contract (cleanup)
- After bake period and once Blue is retired, remove old columns/paths in a later release.
4.2 Event and message compatibility (if applicable)
- Version events (e.g.,
v1, v2) and support dual-read/dual-write temporarily.
- Consumers must tolerate unknown fields; producers must not break existing schemas.
4.3 Rollback implications
- Prefer rollback by traffic flip, not DB rollback.
- Avoid destructive migrations in the release window.
- If a DB rollback is unavoidable, it must be:
- Fast
- Fully automated
- Proven in staging with production-like data volume
- Able to run while traffic is reverted to Blue
5) Observability gates (automated promotion criteria)
5.1 Signals to gate on (compare Green vs Blue)
Golden signals
- Error rate (5xx, handled failures, timeout rate)
- Latency (p50/p95/p99)
- Traffic (request rate, queue depth)
- Saturation (CPU, memory, thread pools, DB connections)
Business KPIs (high value for catching “correct but wrong”)
- Checkout success rate, login success, search results non-empty, etc.
Correctness
- Data integrity counters (e.g., duplicate writes, inconsistent states)
- Consumer lag (Kafka lag, queue age)
5.2 Concrete gate examples (tune to your SLOs)
For each canary step, require all to pass over the analysis window:
Green 5xx rate <= max(Blue 5xx rate + 0.1%, 0.2%)
Green p95 latency <= Blue p95 * 1.10
No sustained increase in DB error rate (e.g., connection exhaustion)
Key business KPI delta >= -0.5% (no more than 0.5% drop)
5.3 Gate implementation
- Use an automated analysis engine (examples: Argo Rollouts Analysis, Flagger, Spinnaker Kayenta, custom PromQL).
- Require:
- Minimum sample size (avoid promoting on too little traffic)
- Noise handling (short spikes shouldn’t fail; sustained regression should)
6) Rollback automation (fast, safe, and default)
6.1 Automatic rollback triggers
Rollback to Blue when any is true:
- Gate failures (error/latency/KPI thresholds breached)
- Synthetics failing N times consecutively
- Crashloop / readiness failures above threshold
- Manual “stop” button by on-call
6.2 Rollback actions (ordered)
- Set Green traffic weight → 0% immediately
- Freeze rollout
- Keep Green running (for debug) but:
- scale to minimal safe capacity, or isolate via auth/IP allowlist
- Auto-create incident artifact
- link dashboards, traces, logs, deploy SHA, diff, config changes
- Optional: auto-disable feature flags introduced in release
6.3 Rollback of state changes
- Default: no DB rollback, because it’s high-risk and slow.
- If you must revert DB:
- Execute a tested rollback migration only if it is non-destructive and fast.
- Otherwise, forward-fix with a hotpatch while serving traffic from Blue.
6.4 Bake + decommission policy
- After full cutover, keep Blue intact for a bake period (e.g., 24h).
- Only then deprovision Blue to reduce cost.
7) End-to-end deployment flow (putting it together)
- Provision Green (same infra class as Blue)
- Run expand migrations (backward compatible)
- Deploy app to Green
- Pre-traffic smoke + synthetic checks
- Start canary (1% → 5% → 25% → 50% → 100%) with observability gates at each step
- Full cutover (Green becomes new “stable”)
- Bake (monitor, run longer synthetics, confirm migration completion)
- Contract migrations in a later release
- Decommission Blue after bake
8) Tooling notes (optional choices)
- Kubernetes: Argo Rollouts or Flagger for traffic shifting + analysis
- AWS: CodeDeploy blue/green + ALB weighted target groups + CloudWatch alarms
- GCP: Traffic Director + Cloud Monitoring SLOs
- General: any LB/service mesh supporting weighted routing + automated metrics analysis
If you share your platform (Kubernetes vs VM-based, cloud provider, database type, and whether you have a service mesh), I can tailor the routing primitives, gate queries (PromQL/CloudWatch), and a concrete rollout spec.