There are a variety of techniques to deploy new applications to production, so choosing the right strategy is an important decision, weighing the options in terms of the impact of change on the system, and on the end-users.
In this post, we are going to talk about the following strategies:
Recreate
: Version A is terminated then version B is rolled out.Ramped
(also known as rolling-update or incremental): Version B is slowly rolled out and replacing version A.Blue/Green
: Version B is released alongside version A, then the traffic is switched to version B.Canary
: Version B is released to a subset of users, then proceed to a full rollout.A/B testing
: Version B is released to a subset of users under specific condition.Shadow
: Version B receives real-world traffic alongside version A and doesn’t impact the response.
Why you should carefully consider your deployment strategy
A well-considered software deployment strategy is crucial for the success of any software delivery team. There are several reasons for this:
- It ensures that software is deployed in a
consistent and repeatable manner
, reducing the risk of errors and downtime. - It allows teams to
easily rollback
to a previous version of the software in case of issues. - It enables teams to deploy software to different environments (e.g. development, staging, production) in a controlled and efficient manner.
- It allows teams to
easily track and measure the success of their deployments
. - It enables teams to take advantage of modern deployment practices such as continuous delivery and canary releases.
Let’s take a look at each strategy and see which strategy would fit best for a particular use case.
1. Recreate
The recreate strategy is a dummy deployment which consists of shutting down version A then deploying version B after version A is turned off. This technique implies downtime
of the service that depends on both shutdown
and boot
duration of the application
.
Pros
:
- Easy to setup.
- Application state entirely renewed.
Cons
:
- High impact on the user, expect downtime that depends on both shutdown and boot duration of the application.
2. Ramped (rolling-update)
The ramped deployment strategy consists of slowly rolling out a version of an application by replacing instances one after the other until all the instances are rolled out.
It usually follows the following process: with a pool of version A behind a load balancer, one instance of version B is deployed. When the service is ready to accept traffic, the instance is added
to the pool. Then, one instance of version A is removed
from the pool and shut down.
Pros
:
- Easy to set up.
- Version is slowly released across instances.
- Convenient for stateful applications that can handle rebalancing of the data.
Cons
:
- Rollout/rollback can take time.
- Supporting multiple APIs is hard.
- No control over traffic.
3. Blue/Green
The blue/green deployment strategy differs from a ramped deployment, version B (green) is deployed alongside
version A (blue) with exactly the same amount of instances. After testing that the new version meets all the requirements the traffic is switched
from version A to version B at the load balancer level.
Pros
:
- Instant rollout/rollback.
- Avoid versioning issue, the entire application state is changed in one go.
Cons
:
- Expensive as it requires double the resources.
- Proper test of the entire platform should be done before releasing to production.
- Handling stateful applications can be hard.
4. Canary
A canary deployment consists of gradually shifting production traffic from version A to version B. Usually the traffic is split
based on weight. For example, 90 percent of the requests go to version A, 10 percent go to version B.
This technique is mostly used when the tests are lacking or not reliable or if there is little confidence
about the stability of the new
release on the platform.
Pros
:
- Version released for a subset of users.
- Convenient for error rate and performance monitoring.
- Fast rollback.
Cons
:
- Slow rollout.
5. A/B testing
A/B testing deployments consists of routing
a subset of users to a new functionality under specific conditions
. It is usually a technique for making business decisions based on statistics, rather than a deployment strategy. However, it is related and can be implemented by adding extra functionality to a canary deployment so we will briefly discuss it here.
This technique is widely used to test conversion of a given feature and only roll-out the version that converts the most.
Here is a list of conditions that can be used to distribute traffic amongst the versions:
- By browser cookie
- Query parameters
- Geolocalisation
- Technology support: browser version, screen size, operating system, etc.
- Language
Pros
:
- Several versions run in parallel.
- Full control over the traffic distribution.
Cons
:
- Requires intelligent load balancer.
- Hard to troubleshoot errors for a given session, distributed tracing becomes mandatory.
6. Shadow
A shadow deployment consists of releasing version B alongside
version A, fork
version A’s incoming requests and send them to version B as well without impacting production traffic. This is particularly useful to test production load on a new feature.
This technique is fairly complex to setup and needs special requirements, especially with egress traffic. For example, given a shopping cart platform, if you want to shadow test the payment service you can end-up having customers paying twice for their order. In this case, you can solve it by creating a mocking service that replicates the response from the provider.
Pros
:
- Performance testing of the application with production traffic.
- No impact on the user.
- No rollout until the stability and performance of the application meet the requirements.
Cons
:
- Expensive as it requires double the resources.
- Not a true user test and can be misleading.
- Complex to setup.
- Requires mocking service for certain cases.
Summary
Choosing the right strategy deployment for your software project is all about finding the best fit for your specific needs. Here are a few things to keep in mind:
- Size and complexity of the project
- Availability & scalability requirements
- Resources available
- Impact on end-users
There are multiple ways to deploy a new version of an application and it really depends on the needs and budget. When releasing to development/staging environments, a recreate or ramped deployment is usually a good choice. When it comes to production, a ramped or blue/green deployment is usually a good fit, but proper testing of the new platform is necessary.
In the end, the right deployment strategy will depend on your project’s specific needs and constraints. It’s important to weight the pros and cons
and choose a strategy that’s the best fit for your team and your project.