Azure Web Apps: Seamless Deployments With Deployment Slots

Suppose you work for a healthcare company that provides its services via a web platform. The user interface for this platform is set up as a PHP web app hosted in Azure App Services. Frequent updates to the app’s source code are rolled out to production to enhance features or address bugs. However, these updates sometimes introduce problems:

  • Undetected bugs: Despite rigorous testing, testers occasionally miss critical bugs, leading to issues in the production environment.
  • Downtime: When bugs are identified, rolling back changes causes service interruptions, which frustrates end-users.
  • Slow deployments: The deployment and compilation process affects app responsiveness, especially during peak usage times, leading to user dissatisfaction.

Is there a better solution to ensure seamless updates without interrupting the services? Yes! Microsoft Azure offers a powerful feature known as deployment slots.

Azure Deployment Slots

Microsoft Azure’s deployment slots provide an efficient and reliable way to manage application updates. With deployment slots, you can maintain both the new and old versions of your application simultaneously. Swapping between the two versions is as simple as a few mouse clicks, eliminating the need for time-consuming code rollbacks. 

What are Deployment Slots, and How Do They Work?

Azure Deployment Slots is a feature in Azure App Services that allows you to create separate environments for deploying and testing your web app before making it available to all end users. Each deployment slot operates as an independent instance of your app, which can be customized for specific purposes, such as: 

  • Staging: To test and validate changes before moving to production.
  • Production: To serve end-users with a stable version of the app.
  • Additional slots: Depending on your pricing plan, you can create slots for QA, testing, or other environments.

Key Features of Deployment Slots

Pre-Warmed Instances

When you deploy to a staging slot, the slot is pre-warmed. This means the app is fully initialized and ready to handle user requests with minimal latency.

Swapping the staging slot into production ensures there is no downtime or cold-start delay.

Seamless Traffic Redirection

During the swap, traffic redirection between slots is seamless, ensuring no user requests are dropped.

Rollback Capability

If unexpected issues arise after swapping a new version into production, you can immediately swap back to the “last known good” configuration.

How Deployment Slots Address the Problem

Bug Detection Before Production

By deploying the new code to a staging slot, testers can validate the app in an environment that mirrors production. This minimizes the risk of undetected bugs. 

No Service Interruptions

Since the app is pre-warmed in the staging slot, swapping to production occurs without downtime, providing uninterrupted services to end-users.

Faster Deployments

Swapping slots is instantaneous compared to traditional deployment methods, significantly reducing the time needed for deployment and improving responsiveness.

Setting Up and Configuring an Azure Web App

1. Create a Web App

Sign in to the Azure portal with your account. Search for App Services and click it.

Search for App Services and click it

Click on Web App.

Click on Web App

Select 1 to 7 values as required for your application, then click on Review + create, followed by Create. The name of the Web App in this demo is webappdemotosrs.

The name of the Web App in this demo is webappdemotosrs

Click on Review + create

Click on Go to resource.

Click on Go to resource

webappdemotosrs (Web App) can be accessed via the Default domain URL.

Accessing via Default domain URL

Accessing via Default domain URL

2. Deployment Slots Creation

Click on the Deployment slots pane.

Click on the Deployment slots pane

Click on Add slot.

Click on Add slot

Give the slot a Name.

Give the slot a Name
Choose whether to clone settings from another slot. If you choose to clone, settings are copied to your new slot from the slot you specify.

Click on Add.

Click on Add
Slot creates with the given name.

Slot creates with the given name

Configure Web App Deployment Settings

In this task, you will configure Web App deployment settings. Deployment settings allow for continuous deployment. This ensures that the app service has the latest version of the application. In the staging slot, select Deployment Center and then select Settings. In the Source drop-down list, select External Git. Notice the other choices.

  • In the repository field, enter: https://github.com/Azure-Samples/php-docs-hello-world.
  •  In the branch field, enter master. Select Save.
  • From the staging slot, select Overview.
  • Select the Default domain link, and open the URL in a new tab.
  • Verify that the staging slot displays Hello World.

Verify that the staging slot displays Hello World

3. Deployment Slots Swap

Click on Swap.

Click on Swap

Click on Start Swap.

Click on Start SwapClick on Start Swap

Once the swapping is completed, a notification will pop up showing its status.

A notification will pop up showing its status

4. After Deployment Slots Swap

Production Default Domain URL output:

Staging Default Domain URL output will be like below

Production Default Domain URL output

This demonstrates that after a deployment slot swap, the production slot begins running the new code while the staging slot reverts to the old code.

Summary

In this article, we learned how to create and use deployment slots in Azure App Service. We used slots to test and stage new versions of our app and swapped those deployment slots. We can swap slots to deploy a tested app to production and roll back a deployed app when unexpected problems arise. When using deployment slots, remember that Azure warms up an app before a swap, and traffic redirection is instantaneous. The result is that your app is deployed without service interruptions or its performance drops.

Source:
https://dzone.com/articles/azure-web-apps-deployment-slots