Lesson 5 of 5 Azure App Service Plans and Web Apps

Releasing Safely with Deployment Slots

This lesson explains deployment slots, how swaps work, and which settings swap or stay with a slot.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe deployment slots and their tier requirements.
  • Explain the steps of a swap and how to roll back.
  • Distinguish between settings that swap and settings that stay with a slot.

What a slot is

A deployment slot is a live app with its own host name, such as contoso-staging.azurewebsites.net, its own content and its own configuration, running on the same App Service plan instances as the production slot. Slots are available in Standard (up to 5 slots), Premium (up to 20) and Isolated tiers. A new slot can clone the configuration of production or another slot, but not its content.

True or false

Slot basics

Exam skills 3.4.8

Check what a deployment slot is and where it runs.

Log in to try this activity Interactive activities are free with an account.

How a swap works

A swap exchanges the source slot (for example staging) with the target slot (usually production) in a way that avoids cold starts. The steps below describe what App Service does.

  1. Apply target settings

    The target slot's sticky settings (slot settings) are applied to all instances of the source slot, which restarts them.

  2. Warm up

    App Service waits for every source instance to restart and sends warm-up requests (to the root or the paths in applicationInitialization).

  3. Switch routing

    When all instances are warm, the routing rules are swapped, so the target slot now serves the new version.

  4. Update the old version

    The previous production content, now in the source slot, receives the source's settings.

Because the old version remains in the staging slot, swapping again rolls back. Swap with preview (multi-phase swap) stops after the first step so that the source can be validated with production settings before the swap is completed or cancelled. Auto swap swaps a slot into production automatically after each deployment to it.

Put in order

What a swap does

Exam skills 3.4.8

Arrange the steps App Service takes when staging is swapped into production.

Log in to try this activity Interactive activities are free with an account.

Sticky and swapped settings

By default, most configuration moves with the content during a swap: general settings, app settings and connection strings that are not marked as slot settings, handler mappings, public certificates, WebJobs content and hybrid connections. Settings that should stay with a slot, such as a staging database connection string, are marked Deployment slot setting on the Environment variables page. Some settings are never swapped: publishing endpoints, custom domain names, non-public certificates and TLS/SSL bindings, scale settings, WebJobs schedulers, IP restrictions, Always On, diagnostic settings, CORS, VNet integration, managed identities and settings ending in _EXTENSION_VERSION.

Traffic routing on the Deployment slots page sends a percentage of production traffic to another slot, for testing in production; users are pinned to the slot with a cookie.

The following diagram shows deployment slot settings, traffic routing and a swap that keep each slot's own database connection.

Deployment slots that keep each database after a swap. Each slot has its own connection string marked as a deployment slot setting, so the value stays with the slot when code swaps. Traffic routing sends 5% of production users to staging before the swap.
The scenario is illustrative.
Sort into groups

Swapped or stays with the slot?

Exam skills 3.4.8

Decide whether each setting moves with the content during a swap.

Log in to try this activity Interactive activities are free with an account.
Worked example

Safe releases

A web app on a Premium v3 plan uses a production database. A staging slot must test new releases against a test database, and after the swap, production must still use the production database. The team also wants to send 5% of users to the new version before swapping. What should you configure?

Create the connection string in each slot with its own database and mark it as a deployment slot setting in both, so it stays with the slot during swaps. Deploy to staging, set traffic routing to send 5% of production traffic to staging, and then swap. Without the slot setting, the swap would move the test database connection string into production.

Check yourself

Do custom domain bindings move during a slot swap?

Show answer

No. Custom domains and TLS bindings always stay with their slot.

Exam Tips

Remember for the exam

  • Slots: Standard up to 5, Premium up to 20; they share the plan's instances.
  • A swap warms up the source before switching; swap again to roll back.
  • Mark slot-specific values as deployment slot settings.
  • Custom domains, TLS bindings, scale settings and managed identities never swap.