DevOps Tutorial · Git and CI/CD · Lesson 15 of 25

Deployment Strategies

Rolling, blue-green and canary deployments, feature flags, and rolling back safely.

Create a free account to save this page, take notes and track your progress. Sign in

Strategies

Strategy How Pros Cons
Recreate Stop old, start new Simple Downtime
Rolling Replace instances a few at a time No extra capacity, default in Kubernetes Old and new versions run together
Blue-green Start a full new environment, switch traffic at once Instant switch and rollback Double capacity during deploy
Canary Send a small share of traffic to the new version, compare, then increase Limits the blast radius of a bad release Needs good metrics and routing

Feature flags separate deploying code from releasing a feature: the code ships switched off and is turned on for some users later, without a deployment.

Automated canary analysis

Compare the canary's error rate and latency with the stable version, and roll back automatically if it's worse.

Automated canary analysisTry it yourself
import random

random.seed(11)

def error_rate(version, requests):
    p = {"stable": 0.004, "canary-good": 0.005, "canary-bad": 0.030}[version]
    return sum(random.random() < p for _ in range(requests)) / requests

def analyse(canary):
    stable = error_rate("stable", 20_000)
    new = error_rate(canary, 1_000)            # 5% of traffic
    verdict = "promote" if new <= stable * 2 + 0.002 else "ROLL BACK"
    print(f"{canary:12} stable {stable:.2%} vs canary {new:.2%} -> {verdict}")

analyse("canary-good")
analyse("canary-bad")

Output

canary-good  stable 0.42% vs canary 0.40% -> promote
canary-bad   stable 0.41% vs canary 1.80% -> ROLL BACK

Rollbacks and databases

Rolling back code is easy only if the database still works with the old version. Use the expand and contract pattern: first add new columns or tables (both versions work), deploy the new code, and remove old columns only in a later release.

Test yourself

Which strategy needs double capacity during a release?

  1. Rolling
  2. Blue-green
  3. Canary
  4. Feature flags
Show answer

Answer: Blue-green

Blue-green runs a complete second environment and switches all traffic at once.

Was this page helpful?