Chuyển đến nội dung chính

Lesson 25: Deployment Strategies — Blue/Green, Canary & Rolling

Compare deployment strategies: Rolling Update, Blue/Green, Canary, A/B Testing. Kubernetes deployment strategies. Argo Rollouts for progressive delivery. Feature flags with LaunchDarkly/Unleash. Rollback strategies.

🏗️ Architecture — Lesson 25 Lesson 25: Deployment Strategies — Blue/Green, Canary & Rolling

Microservices & Micro Frontend system design — From basics to Production

Part 8: CI/CD & Deployment Strategies

xdev.asia

Introduction

Deploying microservices to production is the riskiest time. Deployment strategy decides blast radius when there is a bug — affects 100% of users or only 5%? This article compares strategies and provides guidance on choosing the right one.

Deployment Strategies — Blue-Green, Canary, Rolling


1. Rolling Update

Kubernetes mặc định:

Pod v1 ●●●●●  (5 replicas)

Deploy v2:
Step 1: ●●●●● + ○     (1 new pod v2 starting)
Step 2: ●●●● + ○○      (2 v2 ready, 1 v1 terminated)
Step 3: ●●● + ○○○      (3 v2 ready)
Step 4: ●● + ○○○○
Step 5: ○○○○○           (all v2)

● = v1, ○ = v2

Advantages: Zero downtime, gradual, K8s native Disadvantages: Mixed versions during rollout, rollback slow Use case: Low-risk changes, stateless services


2. Blue/Green Deployment

Blue (current, live):  ●●●●●  ← traffic
Green (new, staging):  ○○○○○  ← no traffic

Test Green thoroughly, then switch:

Blue:  ●●●●●  ← no traffic (standby)
Green: ○○○○○  ← ALL traffic switched instantly

Advantages: Instant rollback (switch back to blue), full testing before live Disadvantages: 2x resources needed, database migration must be backward compatible Use case: Critical services, when instant rollback is needed


3. Canary Deployment ⭐

Step 1: ●●●●● (100% v1)
Step 2: ●●●●○ (90% v1, 10% v2) ← canary
Step 3: Monitor metrics (error rate, latency, CPU)
Step 4a: Metrics OK → ●●●○○ → ●●○○○ → ○○○○○ (promote)
Step 4b: Metrics BAD → ●●●●● (rollback, remove canary)

Advantages: Smallest blast radius, data-driven promotion Disadvantages: Complex setup, needs good monitoring Use case: Most production deployments — recommended default


4. Argo Rollouts (Progressive Delivery)

# rollout.yaml
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: product-service
spec:
  replicas: 5
  strategy:
    canary:
      canaryService: product-service-canary
      stableService: product-service-stable
      steps:
        - setWeight: 5
        - pause: { duration: 5m }
        - setWeight: 20
        - pause: { duration: 10m }
        - setWeight: 50
        - pause: { duration: 15m }
        - setWeight: 100
      analysis:
        templates:
          - templateName: success-rate
        startingStep: 2
        args:
          - name: service-name
            value: product-service

---
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
  name: success-rate
spec:
  metrics:
    - name: success-rate
      interval: 1m
      successCondition: result[0] >= 0.99
      provider:
        prometheus:
          address: http://prometheus:9090
          query: |
            sum(rate(http_requests_total{service="{{args.service-name}}",code=~"2.."}[5m]))
            /
            sum(rate(http_requests_total{service="{{args.service-name}}"}[5m]))

5. Feature Flags

Deploy code to production without enabling for users:

// Feature flag check
const unleash = require('unleash-client');

app.get('/api/products', (req, res) => {
  const products = getProducts();
  
  if (unleash.isEnabled('new-recommendation-engine', {
    userId: req.user.id
  })) {
    // New feature, enabled for specific users
    products.forEach(p => {
      p.recommendations = newEngine.getRecommendations(p.id);
    });
  }
  
  res.json(products);
});

Feature Flags + Canary

1. Deploy v2 with feature flag OFF → 100% users get old behavior
2. Enable flag for 5% users → monitor
3. Gradually increase → 20% → 50% → 100%
4. Remove flag from code after full rollout

6. Decision Matrix

StrategyRiskSpeed ​​CostRollbackBest For
RollingMediumSlowLowSlowLow-risk changes
Blue/GreenLowFastHigh (2x)InstantCritical services
CanaryVery LowMediumLowFastDefault choice
Feature FlagsVery LowInstantLowInstantUX changes

Recommended

E-Commerce Platform:
├── Backend services: Canary (Argo Rollouts) + Auto analysis
├── Micro Frontends: Canary via CDN traffic splitting 
├── Database changes: Blue/Green (backward compatible)
└── UI features: Feature flags (Unleash)

7. Rollback Strategy

ComponentsRollback Method
K8s Deploymentkubectl rollout undo
Argo RolloutAuto-rollback on failed analysis
MFE on CDNPoint to previous version
DatabaseForward migration (never rollback schema)
Feature FlagDisable flag instantly

Summary

  • Rolling Update: K8s default, simple, good for low-risk
  • Blue/Green: instant rollback, 2x cost
  • Canary: smallest blast radius — recommended default
  • Argo Rollouts: automated progressive delivery with analysis
  • Feature Flags: deploy ≠ release, instant enable/disable

Next article: Lesson 26: Full-Stack Observability — Logs, Metrics & Traces