Intermediate LevelDocker & Deployment
How do Blue-Green Deployments achieve zero-downtime releases?
❓ Interview Prompt: Explain the Blue-Green deployment pattern — parallel environments, atomic load balancer cutover, and instant rollback strategy.
Blue-Green Deployment is a zero-downtime release strategy that maintains two identical production environments:
How It Works:
1
Blue (Active): The current live production environment serving 100% of traffic.
2
Green (Staging): An identical environment with the new version deployed and validated.
3
Atomic Cutover: The load balancer routes 100% of traffic from Blue to Green in a single atomic switch.
4
Blue Stays Running: Blue remains idle as an instant rollback target. If Green has issues, switch back to Blue in seconds.
Advantages:
•
Zero Downtime: The cutover is instantaneous — no rolling restart.
•
Instant Rollback: Flip the load balancer back to Blue if issues emerge.
•
Full Testing: Green can be load-tested with production data before the cutover.
Disadvantages:
•
2x Infrastructure Cost: Both environments must run simultaneously.
•
Database Migrations: Schema changes must be backward-compatible with both Blue and Green.
•
State: Session data in Blue containers is lost on cutover (use external session stores like Redis).
Code Implementation Example
bash
# Current state: Blue (v1) is live on port 80
# Step 1: Deploy Green (v2) on a different port
docker run -d \
--name api-green \
-p 3001:3000 \
myapp:v2.0.0
# Step 2: Health check Green environment
curl -f http://localhost:3001/health && echo "Green is healthy"
# Step 3: Run smoke tests against Green
./smoke-tests.sh http://localhost:3001
# Step 4: Atomic cutover — update NGINX upstream to Green
# (In production: update load balancer target group, Ingress, or Traefik rule)
docker exec nginx sh -c "
sed -i 's/api-blue:3000/api-green:3000/' /etc/nginx/conf.d/app.conf
nginx -s reload
"
# Step 5: Monitor Green in production for 15 minutes
# If issues: instant rollback
docker exec nginx sh -c "
sed -i 's/api-green:3000/api-blue:3000/' /etc/nginx/conf.d/app.conf
nginx -s reload
"💡Blue-Green: deploy Green, validate, switch load balancer atomically, keep Blue for instant rollback.
🎯 Interview Key Takeaway
Blue-Green deployment switches traffic atomically between two identical environments — zero downtime, instant rollback, but requires 2x infrastructure cost.
#Blue-Green#Zero Downtime#Deployment#Load Balancer#Rollback#Intermediate
Back to all Docker & Deployment Questions→