Azure Deployment Slot Database

This post explains some of the not so well-known features and configurations settings of the Azure App Service deployment slots. These can be used to modify the swap logic as well as to improve the application availability during and after the swap. Here is what you can do with them:

Azure Deployment Slots is a feature that allows Web Apps, API Apps and Function Apps to run different instances of their application at the same time (known as slots). Slots are exposed via a publicly available endpoint. Azure Deployment Slot is a very useful feature of the Azure App Service. With this feature, it is possible to create one or more slots that can host different versions of your app. You can then swap these deployment slots without causing any downtime for your users. What are Azure Deployment Slots?

Swap based on the status code

During the swap operation the site in the staging slot is warmed up by making an HTTP request to its root directory. More detailed explanation of that process is available at How to warm up Azure Web App during deployment slots swap. By default the swap will proceed as long as the site responds with any status code. However, if you prefer the swap to not proceed if the application fails to warm up then you can configure it by using these app settings:

  • WEBSITE_SWAP_WARMUP_PING_PATH: The path to make the warm up request to. Set this to a URL path that begins with a slash as the value. For example, “/warmup.php”. The default value is /.
  • WEBSITE_SWAP_WARMUP_PING_STATUSES:Expected HTTP response codes for the warm-up operation. Set this to a comma-separated list of HTTP status codes. For example: “200,202” . If the returned status code is not in the list, the swap operation will not complete. By default, all response codes are valid.
Azure Deployment Slot Database

You can mark those two app setting as “Slot Settings” which would make them remain with the slot during the swap. Or you can have them as “non-sticky” settings meaning that they would move with the site as it gets swapped between slots.

Minimize random cold starts

In some cases after the swap the web app in the production slot may restart later without any action taken by the app owner. This usually happens when the underlying storage infrastructure of Azure App Service undergoes some changes. When that happens the application will restart on all VMs at the same time which may result in a cold start and a high latency of the HTTP requests. While you cannot control the underlying storage events you can minimize the effect they have on your app in the production slot. Set this app setting on every slot of the app:

  • WEBSITE_ADD_SITENAME_BINDINGS_IN_APPHOST_CONFIG: setting this to “1” will prevent web app’s worker process and app domain from recycling when the App Service’s storage infrastructure gets reconfigured.

The only side effect this setting has is that it may cause problems when used with some Windows Communication Foundation (WCF) application. If you app does not use WCF then there is no downside of using this setting.

Control SLOT-sticky configuration

Originally when deployment slots functionality was released it did not properly handle some of the common site configuration settings during swap. For example if you configured IP restrictions on the production slot but did not configure that on the staging slot and then performed the swap you would have had the production slot without any IP restrictions configuration, while the staging slot had the IP restrictions enabled. That did not make much sense so the product team has fixed that. Now the following settings always remain with the slot:

Azure Deployment Slot Database
  • IP Restrictions
  • Always On
  • Protocol settings (Https Only, TLS version, client certificates)
  • Diagnostic Log settings
  • CORS

If however for any reason you need to revert to the old behavior of swapping these settings then you can add the app setting WEBSITE_OVERRIDE_PRESERVE_DEFAULT_STICKY_SLOT_SETTINGS to every slot of the app and set its value to “0” or “false”.

swap Diagnostics detector

If a swap operation did not complete successfully for any reason you can use the diagnostics detector to see what has happened during the swap operation and what caused it to fail. To get to it use the “Diagnose and solve problems” link in the portal:

From there click on “Check Swap Operations” which will open a page showing all the swaps performed on the webapp and their results. It will include possible root causes for the failures and recommendations on how to fix them.

In this article, we will see –

  1. how to deploy Azure WebApp,
  2. add deployment slot,
  3. code push to Production and Staging slots
  4. finally, swap the slots

Design and Architecture of Azure Web App Deployment slots is given on the link below –

Deploy Azure WebApp

  1. Login to Azure Portal – https://portal.azure.com
  2. Deploy Azure WebApp using the New menu
  3. Click on Azure WebApp once it is created, click on “Deployment slots” and then click on “Add Slot”
  4. I have slot as “Staging”, and I have chosen not to clone configuration from Production slot. This is being done because we will be deploying different version of the app into both slots.
Azure Deployment Slot Database

Summary –

Production URL – http://sarveshgoel.azurewebsites.net

Staging Slot URL – http://sarveshgoel-staging.azurewebsite.net

Push code to Production and Staging deployment slots

  1. Launch VSTS and open sample web code. I have update the heading on the page to show – Production text. This will be published to the Production slot. Right click on the solution and click on Publish
  2. Select new profile, select Azure App Service. Choose Select Existing since we will be deploying to existing Azure WebApp
  3. Select the Primary slot – sarveshgoel and the code will be pushed there. We will run similar steps for Staging slot.
  4. Now click on Publish, and wait for the confirmation.
  5. Now browse the URL – http://sarveshgoel.azurewebsites.net and you would see the changes that we did initially

Azure Deployment Slot Database Management

Deploy to Staging Slot now

Now repeat the process for Staging Slot but remember to modify the content of Web page, for example – I would change Production to Staging. Another change will from the steps above to deploy to Staging slot

Swap the Azure WebApp Deployment slot now

Azure Deployment Slots Database

Now we have two versions of Web Application running on separate slots, running on their own Web URLs. As explained in the Design and Architecture documentation, purpose of staging slot is to test the code before making it Production.

Please remember, the slots in Production WebApp should be used for Staging environment but not for QA or testing environments.

Now, click on deployment slots on the Azure Portal, click on Swap . Now swap Production with Staging as shown below.

Database

Once you click on Ok, Production becomes Staging and Staging becomes Production within few seconds.

Deployment

Azure Deployment Slot Database Definition

Look at the URLs above, and try using this amazing feature Azure WebApp deployment slot.

Comments are closed.