AI Hints
Home›CI/CD with GitHub Actions Tutorial›Deployment Strategies
CI/CD with GitHub Actions · Lesson 90 of 138

Blue-Green and Canary

Switch or test with a few.

⏱ 2 min read▶ Video at 1:43:52🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Blue green and canary both aim for safer releases. Blue green switches all traffic at once, but keeps the old version ready. Canary tries the new version on a few users first.

Blue-Green and Canary
From the video: Blue-Green and Canary
  • Two safer strategies
  • Switch at once
  • Or try on a few

Blue-green

Blue is live. You deploy the new version to green, which has no users yet, and test it. Then the load balancer switches all traffic to green. If something's wrong, you switch back to blue in seconds.

Blue (live)

  • Old version
  • Serving users
  • Kept as backup

Green (new)

  • New version
  • Tested first
  • Gets all traffic

A canary split

A canary sends a small share of requests, like ten percent, to the new version. This Python script simulates a thousand requests. About a hundred go to version two. If the canary's errors stay low, you raise the share step by step, until it's one hundred percent.

Terminal
cat canary.py
import random
random.seed(1)
hits = {"v1": 0, "v2": 0}
for _ in range(1000):
    version = "v2" if random.random() < 0.1 else "v1"
    hits[version] += 1
print(hits)
python3 canary.py
{'v1': 905, 'v2': 95}

Summary

Blue green switches instantly, with an instant undo. Canary tests on a small share of users first. Next, deploying to a server over SSH.

Key takeaways
  • Blue-green: switch
  • Canary: a few first
  • Watch the metrics
Next up: Deploying over SSH — the simplest deploy