Blue-Green Deployment is a deployment model in DevOps that allows you to effectively avoid glitches, downtimes, outages while performing app service deployment in the production environment, where live customers are accessing the service.
What is the purpose of Blue-Green deployment model? - DevOps
During In-Place deployments, we deploy the app source code directly on to the servers that are serving live customer traffic. Then, we restart the app services on the server, which produce minor downtimes, glitches, errors, and timeouts to the customers who are accessing the service at that time. In the case of failed/improper deployment, the downtime increases, which affects the customer experience of the service. These issues can be eradicated by properly implementing Blue-Green deployment model in our production environment. So, a DevOps professional needs to understand the real purpose of the Blue-Green deployment model for effective implementation.
When & Where we need Blue-Green deployment model? - DevOps
Blue-Green deployment model is not best suited for every production workloads. As a DevOps professional, we need to figure out whether it is needed or not. Suppose, if we are B2B service managing adequate paying customers accessing our service 24/7, then we need to opt for Blue-Green deployment. Here the customers are potential businesses or organizations that rely on our service. They cannot tolerate minor downtimes, glitches, errors, and timeouts because it affects their productivity.
Steps to implement Blue-Green deployment model - DevOps
In DevOps, the basic idea behind Blue-Green deployment model is to gradually switch the customer traffic between two identical fleets of app servers in production environment. The very important component in Blue-Green deployment is the load balancer or proxy, through which the customer traffic enters into the production environment. Many people use Nginx or HAProxy to route customer traffic to app servers. If you are in AWS, you can use Amazon EC2 ELB to route customer traffic to your app servers.
Now, let's assume that current customer traffic is served by Blue fleet app servers, while the Green fleet app servers are offline. Here are the steps to effectively perform Blue-Green deployment in our production environment.
Boot the Green fleet app servers and bring them online.
Deploy the app source code on to the Green fleet app servers. We can use Chef, Ansible, Salt to execute deployments on the app servers. After the deployment, we need to test all the features of the product.
Our customers will face downtimes, glitches, errors, and timeouts if we switch the live customer traffic without doing proper warmup. So, we need to warmup the Green fleet app servers by putting an artificial workload that is equivalent to the production workload handled by Blue fleet app servers.
Gradually switch the customer traffic towards Green fleet app servers by controlling the load balancer or proxy. Our app servers will go down if we switch the entire customer traffic at once. First, we must try switching 5% of the customer traffic from Blue fleet app servers to Green fleet app servers by controlling the load balancer. Then, check the error rate and app performance. If everything is stable, we need to repeat the same by switching the next 20%, 25%, and 50% of the customer traffic.
If the 100% customer traffic is switched to Green fleet app servers, then we can take the Blue fleet app servers to offline mode.
In the next deployment, repeat the above steps vice versa.
Know the best practices in Blue-Green deployment model - DevOps
Learning the best practices in the Blue-Green deployment model is very important for a DevOps professional to perform effective deployments at a very high scale of customer traffic.
Blue-Green deployment model is intended for app services like PHP, Python, Java, NodeJS, Ruby, etc. It is not intended for database services like Elasticsearch, MongoDB, MySQL, Cassandra, Redis, Riak, etc.
Both the Blue and Green fleet app servers belong to a single production environment. We must not consider the Blue and Green app servers are part of different environments.
Always have an eye on error rate and app performance while switching traffic from one fleet to another.
Test the Blue-Green deployment model in a staging environment before taking it to the production environment.
Hope it helps. Thank you.