Deploying a new version used to mean a maintenance window, notifying users, and hoping for the best. Blue-green deployment eliminates downtime: two identical environments, a load-balancer switch, and instant rollback. No more late-night deployments.
The Principle¶
Two environments: Blue (current production) and Green (new version). Deploy to Green, test it, switch the router/LB to Green. Blue remains available as an instant rollback. Problem? Switch back to Blue in seconds.
Implementation with Nginx¶
# Switching from blue to green
upstream app {
server green-server:8080;
# server blue-server:8080; # commented out
}
# nginx -s reload
Database Migrations¶
The biggest challenge. Both versions must work with the same database. Rules: add columns (do not remove them), make backward-compatible changes, use Flyway/Liquibase for versioned migrations. Destructive changes only after a successful switch.
With Docker and Swarm¶
Docker Swarm rolling update is effectively blue-green at the container level.
docker service update --image myapp:2.0 gradually replaces instances.
Zero Downtime is Achievable¶
Blue-green deployment requires investment in infrastructure and discipline around database migrations. But eliminating downtime and having instant rollback is worth it.
Need help with implementation?
Our experts can help with design, implementation, and operations. From architecture to production.
Contact us