An in-depth introduction to Blue Green Deployments



1309 views Backend System Design



Blue Green Deployment is a deployment pattern that reduces the downtime during deployment by running two identical production setups called - Blue and Green.

During deployment when we reboot the API servers there are chances that the incoming request fail because the server is unresponsive for a short period. Also, it might happen that the release had a major bug and we need a quick rollback.

How can we achieve both of them in one shot? The answer is Blue Green Deployment.

Implemention

Blue Green deployment is implemented by having a separate fleet of infrastructure for the old version - Blue and the new version - Green. The new infrastructure is identical to the old one.

The deployment flow

  1. the new deployment artifact is tested and kept ready to be deployed
  2. a parallel infrastructure is set up identical to the existing
  3. the new version is deployed on the new fleet - Green
  4. the correctness of the setup is validated
  5. the proxy is re-configured to now forward 100% of traffic from the Blue (old) setup to the Green (new) setup
  6. a final sanity test is run on the new fleet
  7. the blue fleet is now shut down

Pros of Blue Green Deployment

  1. rollbacks are just a config change and hence quick
  2. downtime during deployment is minimal
  3. deployment is just a flip of a switch
  4. disaster recovery is simple given we already have the automation to build a parallel setup
  5. deployments can now happen during the working hours
  6. debugging a failed deployment is simple as we have the infrastructure with the debug information handy

Possible challenges

  1. during the deployment the infrastructure cost shoots 2x
  2. the stateful application would need to rebuild the state on new servers
  3. the database would have to be shared between the fleets
  4. any schema migration on the database needs to be backward and forward compatible
  5. the API responses have to be forward and backward compatible
  6. setting up this deployment strategy for the first time is difficult

When to use Blue Green Deployment?

  • when you need zero downtime deployment
  • your infrastructure can tolerate 100% traffic switch
  • you can bear the 2x cost of infrastructure during deployment

Points to remember

  • have a solid automation test suite to validate the correctness
  • ensure forward and backward compatibility of API and schema changes
  • infra cost will shoot up hence minimizing the time for which you are running 2x infra

Arpit Bhayani

Arpit's Newsletter

CS newsletter for the curious engineers

❤️ by 17000+ readers

If you like what you read subscribe you can always subscribe to my newsletter and get the post delivered straight to your inbox. I write essays on various engineering topics and share it through my weekly newsletter.




Other essays that you might like


An in-depth introduction to Rolling Deployments

944 views 46 likes 2022-05-27

One of the simplest deployment strategies that make deployment a breeze is Rolling Deployment. It is the most widely ado...

Implementing Vertical Sharding

1124 views 75 likes 2022-05-25

Sharding is super-important when you want to handle the traffic that cannot be handled through one server. Sharding come...

An in-depth introduction to Blue Green Deployments

1309 views 60 likes 2022-05-18

Deployments are a pain if we are unsure about our release changes. But sometimes even if we know our changes well, somet...

An in-depth introduction to Canary Deployments

1982 views 117 likes 2022-05-16

Deployments are stressful; what if something goes wrong? What if you forgot to handle an edge case that was also missed ...


Be a better engineer

A set of courses designed to make you a better engineer and excel at your career; no-fluff, pure engineering.


System Design Masterclass

A masterclass that helps you become great at designing scalable, fault-tolerant, and highly available systems.

Enrolled by 700+ learners

Details →

Designing Microservices

A free course to help you understand Microservices and their high-level patterns in depth.

Enrolled by 17+ learners

Details →

GitHub Outage Dissections

A free course to help you learn core engineering from outages that happened at GitHub.

Enrolled by 67+ learners

Details →

Hash Table Internals

A free course to help you learn core engineering from outages that happened at GitHub.

Enrolled by 25+ learners

Details →

BitTorrent Internals

A free course to help you understand the algorithms and strategies that power P2P networks and BitTorrent.

Enrolled by 42+ learners

Details →

Topics I talk about

Being a passionate engineer, I love to talk about a wide range of topics, but these are my personal favourites.




Arpit's Newsletter read by 17000+ engineers

🔥 Thrice a week, in your inbox, an essay about system design, distributed systems, microservices, programming languages internals, or a deep dive on some super-clever algorithm, or just a few tips on building highly scalable distributed systems.



  • v12.4.4
  • © Arpit Bhayani, 2022

Powered by this tech stack.