Skip to content

Deployment Strategies

Deploy safely with rolling updates, blue-green deployments, and canary releases.

What you'll learn

  • Common deployment strategies and when to use each
  • Rolling updates for zero-downtime deploys
  • Blue-green deployments for instant rollbacks
  • Canary releases for progressive rollouts

Concept

Choosing a Strategy

How you deploy code to production is just as important as the code itself. A good deployment strategy minimizes downtime, reduces risk, and enables fast rollbacks. The simplest approach — stop the old version, start the new — causes downtime and risks exposing all users to bugs at once. Modern strategies like rolling updates, blue-green deployments, and canary releases address these problems in different ways.

Rolling Updates

A rolling update replaces instances of the old version gradually, one at a time. If you have five servers, the deploy updates one server to the new version, verifies it is healthy, then moves to the next. This achieves zero downtime because some servers always serve traffic. Kubernetes does rolling updates by default. The risk is that during the rollout, both old and new versions serve traffic simultaneously, so they must be compatible.

Blue-Green Deployments

In a blue-green deployment, you maintain two identical production environments: blue (current) and green (new). You deploy the new version to green, test it, then switch the router to send all traffic to green. If something goes wrong, you switch back to blue instantly — no redeployment needed. The tradeoff is that you need twice the infrastructure, and database migrations must be carefully designed to work with both versions.

Canary Releases

A canary release sends a small percentage of traffic to the new version — say 5% — while the rest goes to the old version. You monitor error rates and performance metrics. If everything looks good, you gradually increase the percentage: 5%, 25%, 50%, 100%. If problems appear, you stop the rollout. Canary releases limit the blast radius of bad deploys and are the gold standard for large-scale production systems.

Choosing the Right Strategy

For small applications with low traffic, a simple rolling update may suffice. For critical services with high traffic, canary releases provide the safest rollout. Blue-green is ideal when you need instant rollback capability and can afford double infrastructure. Feature flags offer another approach — deploy the new code but gate the feature behind a flag, enabling it for a subset of users. The right strategy depends on your traffic volume, infrastructure budget, and risk tolerance. Start simple and adopt more sophisticated strategies as your system grows.

Example

              # Rolling update with Docker Swarm
docker service update --image myapp:v2 myapp_service

# Blue-green deployment script
docker run -d --name app_green -p 8081:80 myapp:v2
curl -f http://localhost:8081/health || exit 1

# Switch traffic: update nginx upstream to green
sudo nginx -s reload

# Stop the old blue version after verification
docker stop app_blue && docker rm app_blue

# Canary: route 10% of traffic to the new version
# (typically done with a load balancer or service mesh)
echo "Canary deploy: 10% traffic to v2"
            

Rolling updates replace instances one at a time. Blue-green runs two environments and switches traffic. Canary sends a small percentage of traffic to the new version first.

Try it

Common mistakes

The mistake

Deploying without a health check

The fix

Always verify the new version is healthy before routing traffic to it. Use a /health endpoint and automated checks. Without this, you risk sending traffic to a broken deployment.

The mistake

Not having a rollback plan

The fix

Before deploying, know exactly how to roll back. With blue-green, switch the router. With versioned images, deploy the previous tag. Practice rollbacks before you need them.

Practice Deployment Strategies

3 exercises

Practice Deployment Strategies

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors