Blue-green Deployments, A/B Testing, and Canary Releases
Methods like blue-green and canary deployments, along with A/B testing, have been staples of DevOps. This article will clarify the differences between each one.
Join the DZone community and get the full member experience.
Join For Freea lot of teams i talk to recently are very interested in “devops” (whatever that means…seems to mean different things to different people?) and when we sit down and talk about what that really means, the direction of the conversation can go down many interesting paths. and sometimes, the path it goes down makes people feel very uncomfortable . i was talking with a team a while back about deployment best practices, hot deployments, rollbacks, etc. and when i mentioned blue-green deployments , they became a bit queasy. another team couldn’t understand why doing something they’ve always done was not such a good thing .
blue-green deployments have been practiced at places like amazon for 10+ years. they’re a safe, proven, method. now, blue-green deployments are not a silver bullet, but there’s an element of usefulness to them. but what about a/b testing? or even canary testing? with all of the #microservices, devops, and cloud-native talk, there’s a lot of discussion about them, but i wanted to clarify their differences.
blue green deployments
pleaes see martin fowler’s link about blue-green deployments . it provides the overall gist. it’s basically a technique for releasing your application in a predictable manner with an goal of reducing any downtime associated with a release . it’s a quick way to prime your app before releasing, and also quickly roll back if you find issues.
simply put, you have two identical environments (infrastructure) with the “green” environment hosting the current production apps (app1 version1, app2 version1, app3 version1 for example):
now, when you’re ready to make a change to app2 for example and upgrade it to v2, you’d do so in the “blue environment”. in that environment you deploy the new version of the app, run smoke tests, and any other tests (including those to exercise/prime the os, cache, cpu, etc). when things look good, you change the loadbalancer/reverse proxy/router to point to the blue environment:
you monitor for any failures or exceptions because of the release. if everything looks good, you can eventually shut down the green environment and use it to stage any new releases. if not, you can quickly rollback to the green environment by pointing the loadbalancer back.
sounds good in theory. but there are things to watch out for.
- long running transactions in the green environment. when you switch over to blue, you have to gracefully handle those outstanding transactions as well as the new ones. this also can become troublesome if your db backends cannot handle this (see below).
- enterprise deployments are not typically amenable to “microservice” style deployments – that is, you may have a hybrid of microservice style apps, and some traditional, difficult-to-change-apps working together. coordinating between the two for a blue-green deployment can still lead to downtime
- database migrations can get really tricky and would have to be migrated/rolledback alongside the app deployments. there are good tools and techniques for doing this, but in an environment with traditional rdbms, nosql, and file-system backed dbs, these things really need to be thought through ahead of time; blindly saying you’re doing blue green deployments doesn’t help anything – it could actually hurt.
- you need to have the infrastructure to do this
- if you try to do this on non-isolated infrastructure (vms, docker, etc), you run the risk of destroying your blue and green environments
as i’ve said, there are good techniques to overcome these challenges and make this deployment style work out very nicely, including plugging into a continuous deployment pipeline, but don’t jump into it trivially.
a/b testing
a/b testing is not blue-green deployments. i’ve run into groups that mistake this. a/b testing is a way of testing features in your application for various reasons like usability, popularity, noticeability, etc, and how those factors influence the bottom line. it’s usually associated with the ui of the app, but of course the backend services need to be available to do this. you can implement this with application-level switches (ie, smart logic that knows when to display certain ui controls), static switches (in the application), and also using canary releases (as discussed below).
the difference between blue-green deployments and a/b testing is a/b testing is for measuring functionality in the app. blue-green deployments are about releasing new software safely and rolling it back predictably. you can obviously combine them: use blue-green deployments to deploy new features in an app that can be used for a/b testing.
canary releases
lastly, canary releases are a way of sending out a new version of your app into production that plays the role of a “canary” to get an idea of how it will perform (integrate with other apps, cpu, memory, disk usage, etc). it’s another release strategy that can mitigate the fact that, regardless of the immense level of testing you do in lower environments, you will still have some bugs in production. canary releases let you test the waters before pulling the trigger on a full release.
the faster feedback you get, the faster you can fail the deployment, or proceed cautiously. for some of the same reasons as the blue-green deployments, be careful of things above to watch out for; ie, database changes can still trip you up.
summary
all of these strategies can be implemented regardless of whether you’re using a particular cloud technology. but as you can imagine, technologies such as docker and kubernetes can be greatly helpful (if not even have provisions built in) for implementing these strategies. for example, openshift and fabric8 greatly simplifies using docker and kubernetes by providing the tooling necessary to use these technologies without having to worry about the underlying details. a couple great videos to share that demonstrates this tooling and the out of the box deployment capabilities that i’ve discussed above:
-
veer muchandi demonstrates
- james rawlings demonstrates canary releases with full ci/cd built in with fabric8v2
Published at DZone with permission of Christian Posta, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments