Docs / Cloud & DevOps / Blue-Green Deployments: Zero-Downtime Releases

Blue-Green Deployments: Zero-Downtime Releases

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 126 views · 2 min read

What Is Blue-Green Deployment?

Blue-green deployment maintains two identical production environments. At any time, one is live (blue) and one is idle (green). New releases deploy to the idle environment, then traffic switches over.

How It Works

  1. Blue is currently serving production traffic
  2. Deploy new version to Green
  3. Run tests against Green
  4. Switch the load balancer to point to Green
  5. Green is now live; Blue becomes idle
  6. If problems occur, switch back to Blue instantly

Implementation with Nginx

# /etc/nginx/conf.d/upstream.conf
upstream app {
    server 127.0.0.1:3001;  # Blue
    # server 127.0.0.1:3002;  # Green (uncomment to switch)
}

Scripted Switchover

#!/bin/bash
CURRENT=$(grep "server 127" /etc/nginx/conf.d/upstream.conf | grep -v "#" | awk '{print $2}' | tr -d ';')

if [[ "$CURRENT" == "127.0.0.1:3001" ]]; then
    NEW_PORT=3002
    NEW_ENV="green"
else
    NEW_PORT=3001
    NEW_ENV="blue"
fi

echo "Deploying to $NEW_ENV (port $NEW_PORT)..."
# Deploy application to the new port
# Run health checks
curl -f http://127.0.0.1:$NEW_PORT/health || exit 1

# Switch traffic
sed -i "s/server 127.0.0.1:.*/server 127.0.0.1:$NEW_PORT;/" /etc/nginx/conf.d/upstream.conf
nginx -t && systemctl reload nginx
echo "Traffic switched to $NEW_ENV"

Benefits

  • Zero downtime — no gap between old and new version
  • Instant rollback — switch back in seconds
  • Test in production — verify the new version before switching

Considerations

  • Requires 2x the server resources (two environments)
  • Database migrations need careful handling
  • Session state may need external storage (Redis)

Was this article helpful?