Strategies for Deploying Web Applications to Production
Tags: devops, backend
Published: 2023-08-29 07:47:49

## Introduction 

There are a variety of ways and techniques by which web applications are deployed to production. These techniques are called deployment strategies.

The choice of deployment strategy can make or break a business as it has a direct impact on user experience. It is therefore imperative to pick a strategy that fits the needs of the application.

There are a plethora of deployment strategies, some of the more common techniques include:

**Continuous Deployment**: In this strategy, new versions of an application are immediately deployed to production as soon as they pass automated testing. This method allows for the latest code changes to be available to end users. This method is suitable for businesses that develop new features constantly and want to get them to production quickly. It however requires robust testing to work properly. 

**Blue/Green Deployment**: Here two versions of an application are deployed in two separate environments. The blue environment contains the stable version of the application, while the green environment contains the new version of the application.  Requests are initially routed to the blue environment until the green environment has been tested and found to be stable. Thereafter, requests are routed to the green environment at the load balancer level. In this strategy, the effect of a failed or unstable deployment is minimal however, it's an expensive strategy as it requires double resources as well as the possible issues of slow runouts.

**Canary deployment**: This deployment technique involves releasing the updated version of an application in increments i.e. to a subset of users at a time and then gradually increasing the number of users until all users are using the new version. This method is often used when testing is minimal and developers have little confidence in the stability of the new application.

**Recreate deployment**: Here, the old application is simply shut down and the new application is then deployed in its place. This strategy is straightforward however, there will always be downtime while the old application is shut down and the new one is deployed. This can significantly impact user experience. 

**Shadow deployment**: In this strategy, both old and new applications are deployed. However, only output from the stable application is sent to users. The requests sent to the stable application are copied and sent to the new application. This allows the developers to monitor and compare the outputs and results from both applications. While this method allows the developers to test a new application live, it can be expensive and complex to set up. 

**Ramped/ Rolling Deployment**: Much like the Canary deployment strategy, the new application is deployed in increments or gradually. However, unlike the Canary method where it is deployed to a subset of users, in this method the new application is gradually deployed to a subset or instances of servers. 

There are more strategies used by companies including phased deployment,  A/B testing, ring deployment, and feature flags among others and all have their merits and demerits. 

If I were to pick a strategy, I'd pick the recreate deployment strategy if my company was still a startup and very young and use monitoring to determine times when my users were least active to redeploy. Otherwise, I'd go for a blue/green strategy or continuous delivery strategy.

However, the choice of deployment strategies to use is often dependent on a variety of factors such as resources available, the complexity of the project and end users among others. 

What strategy would you pick and why?