--- name: deploy description: Advanced deployment strategies. Blue-green, canary releases, progressive rollouts, automated rollback, feature flag coordination, zero-downtime migrations, risk mitigation. --- # Deploy — Advanced Deployment Strategies ## Activate When - User invokes `/godmode:deploy` - User says "deploy with zero downtime," "canary release," "blue-green deployment" - User needs rollback strategy for a risky change - Feature flags need orchestration for a complex rollout - Database migrations or infrastructure changes require zero-downtime approach - Godmode orchestrator detects high-risk changes during `/godmode:ship` ## Workflow ### Step 1: Assess Deployment Context Characterize the change and determine the correct deployment strategy: ``` DEPLOYMENT ASSESSMENT: Change type: Risk level: Rollback complexity: Change characteristics: - [ ] Backward compatible (old code works with new data) - [ ] Forward compatible (new code works with old data) - [ ] Database schema changes involved - [ ] API contract changes (breaking/non-breaking) - [ ] Infrastructure changes (new services, topology) - [ ] Feature flags available - [ ] Stateful components affected (sessions, caches) Current environment: ``` ### Step 2: Blue-Green Deployment Two identical environments, instant switchover: ``` BLUE-GREEN DEPLOYMENT PLAN: LOAD BALANCER → routes 100% to active environment [BLUE env: v1.0 (live)] ←── current traffic [GREEN env: v1.1 (idle)] ←── deploy here, then switch ``` ### Step 3: Canary Release Route a small percentage of traffic to the new version: ``` CANARY RELEASE PLAN: LOAD BALANCER (traffic splitting) 95% → [STABLE: v1.0, N instances] 5% → [CANARY: v1.1, 1 instance] Gradually shift: 5% → 25% → 50% → 100% based on metrics ``` ### Step 4: Progressive Rollout Percentage-based traffic shifting with automated gates: ``` PROGRESSIVE ROLLOUT PLAN: | Stage | Traffic | Duration | Gate | Rollback | |--|--|--|--|--| | 1. Smoke | 0% (int) | 5 min | Auto | Auto | | 2. Seed | 1% | 10 min | Auto | Auto | | 3. Low | 5% | 15 min | Auto | Auto | | 4. Med | 25% | 30 min | Manual | Auto | | 5. High | 50% | 30 min | Manual | Auto | | 6. Full | 100% | Monitor | Manual | Manual | Gate criteria: Auto gate: pass if all success metrics within threshold for full duration Manual gate: auto gate + human approval required to proceed ``` IF health check fails post-deploy: auto-rollback. IF canary error rate >1%: abort promotion. ### Step 5: Automated Rollback Define rollback criteria and execution plan: ``` ROLLBACK PLAN: AUTOMATIC ROLLBACK TRIGGERS | Trigger | Threshold | Window | |--|--|--| | HTTP 5xx rate | > 1% | 2 min | | P99 latency | > 2x baseline | 5 min | | Error log rate | > 3x baseline | 5 min | | Health check failures | > 2 consec. | immediate | | Business metric drop | > 10% | 15 min | | Memory usage | > 90% | 5 min | | CPU usage | > 95% | 5 min | ``` ### Step 6: Feature Flag Orchestration Coordinate feature flags with deployment stages: ``` FEATURE FLAG ROLLOUT PLAN: | Flag | Stage 1 | Stage 2 | Stage 3 | Full | |--|--|--|--|--| | new-checkout-ui | internal | 5% users | 50% | 100% | | payment-v2-api | internal | internal | 5% | 100% | | new-recommendation | OFF | OFF | 25% | 100% | Flag dependencies: payment-v2-api REQUIRES new-checkout-ui (cannot enable v2 without new UI) new-recommendation INDEPENDENT (toggle separately) Kill switches: Each flag has a kill switch that disables it within 30 seconds ``` ### Step 7: Zero-Downtime Migration Strategies For database and infrastructure changes that cannot tolerate downtime: #### Database Schema Migration (Expand-Contract Pattern) ``` ZERO-DOWNTIME SCHEMA MIGRATION: Phase 1: EXPAND (deploy with old + new schema) Migration: Add new column/table (nullable, with defaults) Code: Write to BOTH old and new locations Duration: Deploy and verify writes are dual-writing Phase 2: MIGRATE (backfill existing data) Script: Batch-copy data from old to new location Verification: Row counts match, data integrity checks pass Duration: Depends on data volume (estimate: