Azure Cloud Service Deployment Slots

Every App Service resource in Azure has the ability to have multiple deployment slots configure. These deployments slots are a feature than can greatly help with the implementation of streamlined testing, staging, and deployment process. Along with the ability to configure multiple hosting environments, the use of Deployment Slots enables zero downtime when deploying application changes, or even rolling back a failed deployment.

Creating Deployment Slots

This can be done with a few clicks from the Azure Portal. Follow the instructions below to create your first app service slot: Navigate to your Azure App Service that you created in your environment. Click on “Deployment Slots” in the left panel and click “Add Slot” to create a new slot. Adding Deployment Slot.

  1. Also, Service Fabric only provides the capability to run applications. It doesn’t provide features like authentication and deployment slots, like Azure App Services does. You can run the Service Fabric framework anywhere. On-premises, on your own computer, in Azure or in another cloud. It is not Azure specific. Virtual Machines.
  2. If a cloud service has a deployment in either slot, the entire cloud service is pinned to a specific cluster. This means that if a deployment already exists in the production slot, a new staging deployment can only be allocated in the same cluster as the production slot.

Deployment slots are a feature of Azure App Service Plans. As a result, every App Service resource (Web App, Web API, Mobile App) in Microsoft Azure has the ability to create up to 4 additional deployment slots with the Standard tiers, and up to 20 deployment slots with the Premium tiers.

Each App Service (in Standard tiers) can have up to 4 additional Deployment Slots in addition to the Production slot.

Slots

Each Deployment Slot allows for a separate instance of the application to be hosted in isolation from the other deployment slots and production slot of the App Service. The VM behind each Deployment Slot is the same VM Instance that hosts the production deployment slot. This means that the App Service and 4 additional Deployment Slots will all be hosted in and share the same VM Instance and resources.

To create App Service Deployment Slots in the Azure Portal, just navigate to the App Service, select the Deployment slots section and click the Add Slot button to create a new Deployment Slot.

Additionally, in order to use the Deployment Slots feature of Azure App Service, the pricing tier must be either Standard or Premium. The Free, Shared, and Basic pricing tiers do not support deployment slots.

It’s important to keep in mind that all Deployment Slots share the same VM Instance and server resources.

Deployment Slot URL / Endpoint

Azure App Service applications get a unique URL that is made up of the App Service Name as the subdomain of the azurewebsites.net domain. In the above screen shot, the App Service Name is “testapp2063” which means the URL / endpoint for the Production slot of the App Service is located at testapp2063.azurewebsites.net.

When creating Deployment Slots each slot gets it’s own URL / Endpoint. The endpoint for each deployment slot derives from the endpoint for the Production slot by appending the name of the deployment slot with a hyphen.

With an App Service named “testapp2063” the URL / Endpoint for the following deployment slots will have the following values:

  • dev => testapp2063-dev.azurewebsites.net
  • test => testapp2063-test.azurewebsites.net
  • stage => testapp2063-stage.azurewebsites.net

Deployment Slot Swapping

Swapping Deployment Slots is the method of copying the currently deployed application code and settings of one deployment slot and swapping it with another. Swapping allows for the deployment of application code to be done from one environment to another very quickly. It also allows for a couple new deployment techniques that didn’t exist in traditional server hosting.

To swap Deployment Slots from the Azure Portal, just navigate to the list of Deployment Slots for an App Service or navigate to the specific Deployment Slot that needs to be swapped. Then, click the Swap button and specify which Deployment Slot to swap with. See the above screenshots for reference of where the Swap button is located within the Azure Portal.

When an application is deployed using Deployment Slot swapping, there is zero downtime

When an application is deployed using Deployment Slot swapping, there is zero downtime of the application. The way this is implemented is by just rerouting the Deployment Slot Endpoint between the Deployment Slots being swapped. Both deployment slots remain running and actively responding to client requests throughout the swap.

Staged Deployment

The technique of performing a Staged Deployment allows for application code to be deployed to a non-production deployment slot (such as one named stage) to test or verify functionality is working as expected. Then once everything has been verified, the Stage deployment slot can be swapped with Production making the staged application deployment the new Production instance of the application.

Incremental Deployment

There are times when deploying application changes might require additional changes other than just deploying the latest code. These requirements could be running SQL scripts or some other post deployment step necessary to fully deploy the latest code. Deploying to a Stage deployment slot can allow for these Incremental steps to be performed after the code is deployed in a way that can be tested and verified before deploying to production.

Slots

Rollback Deployment

Every once in awhile a deployment fails for some reason. Maybe files end up corrupt, a major bug is found, or some other reason for failure. In these cases, it’s necessary to rollback a deployment. Using Deployment Slots, a deployment can be rolled back easily buy just swapping the Deployment Slots back.

Basically, swap Stage with Production to deploy new changes. When a major bug is found that requires a rollback, then the Production and Stage Deployment Slots can be swapped back. This allows for the old application code to be rolled back into Production in a matter of minutes. This leads to greatly decreased downtime in the event of a deployment failure.

Chris is the Founder of Build5Nines.com and a Microsoft MVP in Azure & IoT with 20 years of experience designing and building Cloud & Enterprise systems. He is also a Microsoft Certified: Azure Solutions Architect, developer, Microsoft Certified Trainer (MCT), and Cloud Advocate. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.

Azure App Services is extremely useful for developers. It offers Web Apps, API Apps, Mobile Apps and Function Apps (that run Azure Functions). All of these apps are incredibly powerful and can literally get you up and running in minutes. They provide a host of amazing features that you can leverage, like (auto)scaling, easy authentication, offline sync (for Mobile Apps), hybrid connections and many, many more. One feature that all of these apps share, is probably the most underrated one that many people don’t know about: deployment slots.

What Are Deployment Slots?

Deployment slots are incredible! They are the reason for many people to start using Azure App Services, like Web Apps. Let me explain why:
Suppose that you have a Web App. You run your website in it and it has an URL like production.website.com. In Azure App Services, you can very easily add a deployment slot. This is actually a full-fledged App Service, in this case a Web App, that sits next to you original Web App. The deployment slot has a different URL, maybe something like staging.website.com. Users use your website that is in the original Web App, because that is your production environment. You can deploy a new version of the website in the deployment slot, just so that you can test it before it goes live.
You could also do that in another Web App. But here is the magic of deployment slots: You can now Swap the deployment slot with production. When you do this, users will notice almost nothing and experience no downtime. The swap functionality of the deployment slot takes care of this magic. Isn’t that awesome?

Deployment Slot Facts

Before I tell you even more things that make deployment slots awesome, let me state out the facts about deployment slots:

  • A deployment slot is a full-fledged App Service that lives within the same App Service Plan as your original App Service
    • This means that deployment slots use some of the resources in the App Service Plan, which could influence the performance of your main App Service
  • The original App Service is also called the production slot
  • Deployment slots can copy the configuration (AppSettings and Connectionstrings) of the original App Service or other deployment slots
  • Your App Service needs to (at least) be in the Standard Pricing tier
  • You can create 4 deployment slots next to your original App Service in the Standard Pricing tier
  • And you can create 19 deployment slots next to your original App Service in the Premium Pricing tier
  • When you scale a deployment slot (up or out), you also scale all the other slots of the App Service. This is because all slots share the same App Service Plan
  • If you have installed any site extensions, you need to do that again in a deployment slot as it is a new App Service instance
  • Deployment slots have a different URL then the original App Service. This URL is based on the name you give the deployment slot, for instance “staging” can become http://website-staging.azurewebsites.net

Alright, let’s take a look at how to setup deployment slots and what the major benefits are in more detail.

Setting up Deployment Slots

Creating a deployment slot is very easy and, as always, there are many ways to do it. You can use the Azure Portal, Azure CLI, Azure PowerShell and the Azure Management API. I’ll show you how to do it using the Azure Portal.
In the Azure Portal, navigate to your App Service - let’s say it’s a Web App - and click the deployment slots menu item:
Now you see the Add Slot button, which opens the Add Slot dialog, to the right of the screen. Here, you need to enter a name, and choose if you want to copy the configuration from another slot, or not at all. Click OK and voila, you have a deployment slot!

Choosing to copy the configuration is important, because your app probably does things like connect to a database or cache and has specific connectionstrings in these settings.

Visit my Pluralsight course for a full video tutorial about setting up and using deployment slots.

Deploying your app to deployment slots

When you have created a deployment slot, it is empty, just like when you create a new App Service. You need to deploy a version of your app to the deployment slot before you can use it.
You can use the same tools and techniques that you use to deploy your app to the App Service: through Visual Studio, using something like VSTS (Visual Studio Team Services) or Octopus Deploy, using Web Deploy or any number of other technologies. Selecting a deployment slot to deploy to from Visual Studio looks like this:

Swap and Rollback

One of the major benefits of deployment slots is that you can swap them. What does that mean?

Swapping

Suppose that I have a website deployed in a Web App. This Web App has the custom URL https://www.azure-overview.com/. I have created a new version of the website and want to test it before publishing it. So I create a deployment slot called staging, which has the URL http://azureoverview-staging.azurewebsites.net. I’ve made sure that the slot has the same configuration values so that I use the same database and cache as production does. I’ve deployed the new website in the deployment slot and I’m happy with my changes and want to deploy to production. I can do this by performing a swap:
I can do this from the Azure Portal, Azure CLI, Azure PowerShell and the Azure Management API. In the Azure Portal, I can choose what the source and destination slots are and click OK. This will swap the slots and will deploy my changes to production. Here’s the thing: Users will experience no downtime!

And that’s because a swap does the following:

  • The source slot will be warmed-up. Azure does this by firing a couple requests into the root of the slot. You can also configure custom warm-up rules
  • Swaps the Virtual IP addresses of the source and destination slots, thereby swapping the URLs of the slots
  • It also applies (or keeps, depending on how you see it) certain settings that are specific to the target slot:
    • Publishing endpoints
    • Custom Domain Names
    • SSL certificates and bindings
    • Scale settings
    • WebJobs schedulers

This results in a seamless transition to production. Users experience virtually no downtime. I say virtually because users that are in the midst of doing something that depends on state that is in-memory of the Web App, will lose this state. But you shouldn’t keep state locally in an App Service anyways in Azure as you should assume that everything in Azure is volatile.

Rollback

After a swap, the “old” website will be in the staging slot and the “new” website in the production slot.
If you aren’t happy with the version in production, you can easily rollback your deployment. Simply swap back to reverse the effect!

Swapping options

You can swap manually, but you have more options:

Auto Swap

You can choose to swap automatically to a slot when there is a new version of your app in a deployment slot – this is called Auto Swap. Simply enable it in the Application Settings of the deployment slot:

Swap with preview

Azure Cloud Service Deployment Slots Online

You can choose to swap with preview when you perform a swap from the Azure Portal. This does the following:

  • It performs the swap in stages
  • It applies the configuration elements of the destination slot to the source slot, so that you can test if everything works as expected, before the actual swap happens
  • (if you complete the swap), it does the same as in a manual swap, warm-up the slot and perform the swap
Swap and VSTS

If you use something like VSTS (Visual Studio Team Services), you can also leverage deployment slots and the swap feature. You can deploy a new version of your app to a deployment slot and then swap it using steps in a release definition. The illustration below shows this for a release definition in VSTS:

Testing in Production

Besides swapping, deployment slots offer another killer feature: testing in production. Just like the name suggests, using this, you can actually test in production. This means that you can route a specific percentage of user traffic to one or more of your deployment slots:
With testing in production, you can have some users use the new version of your application. This way, you can see if and how they use new features. In order to find this out, you need to make sure that you monitor everything, with something like Stackify Retrace.

Setup

Testing in production is easy to setup. In the Azure Portal, choose the testing in production menu option in your App Service.
Here, you can choose the deployment slots that you want to route traffic to (or add new ones) and assign a percentage of traffic to them. That’s it! Now users will be routed to your deployment slots – super powerful!

Conclusion

Slots

Azure Cloud Service Deployment Slots Free

Deployment slots are awesome and I hope that you give them a chance. You can use them for all sorts of things, but there are also things to keep in mind. Here is the quick overview:

Pros:

  • Using the **swap **feature gives you zero-downtime deployments
  • You can test the new version of your app using the testing in production feature
  • Deployment slots are great to verify a new version of an app before it goes live

Cons:

  • A deployment slot is a full-fledged App Service that lives within the same App Service Plan as your original App Service, which might impact the performance of your original App Service
  • A deployment slot is a new App Service. This means that you have to reinstall any site extensions that you have installed in you App Service
  • Your App Service needs to (at least) be in the Standard Pricing tier
  • You can’t scale a deployment slot, separate from other deployment slots in the App Service. This makes a deployment slot not suitable for performance testing – you should use a separate App Service for that

Start using deployment slots and use them wisely! Let me know what you think in the comments.