Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 31 of 47
❮Prev Next❯

App Service Deployment Slots and Swaps

Module 3: Compute ⏱ 10 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    30-second answer

    A deployment slot is a live copy of your web app with its own hostname (<app>-staging.azurewebsites.net), running on the same App Service plan. Slots need Standard (5 slots) or Premium v3 (20 slots). You deploy to staging, test it, then swap: App Service applies production's settings to staging, warms up its instances and only then switches traffic, so there's no cold start, and swapping again rolls back. App settings and connection strings marked Deployment slot setting stay with their slot. Custom domains, certificates and TLS settings, scale settings, IP restrictions and managed identities never swap. Swap with preview pauses after warm-up, and traffic routing can send a percentage of users to a slot.

    Simulate it » No Azure account needed

    Exam objective: 3.4.8 Configure deployment slots for an App Service. (Skills measured as of April 17, 2026)

    Simulations

    Feel it before you read it. No account needed, nothing leaves this page.

    Azure portal: Add a staging slot, set slot settings and swap into production Add a staging slot, mark slot settings and swap.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    Open <strong>Deployment → Deployment slots</strong>. The plan is <strong>Standard</strong>, so it allows 5 slots (Premium v3 allows 20). Select <strong>+ Add slot</strong>.

    👆 Click the glowing item in the portal to continue

    Read the steps as text
    1. Open Deployment → Deployment slots. The plan is Standard, so it allows 5 slots (Premium v3 allows 20). Select + Add slot.
    2. Name it staging and clone settings from production. A slot is a live app with its own hostname, running on the same plan.
    3. In Environment variables, tick Deployment slot setting for values that belong to the slot, like ENVIRONMENT and the payment endpoint. Those stay put during a swap; the rest travel with the code.
    4. Deploy v2 to staging and test it on its own URL. Optionally send it 10% of real traffic. Then select Swap.
    5. Source staging, target production. App Service first applies production’s slot settings to staging and warms up its instances, then switches them. Swap with preview pauses after that first phase so you can check.
    6. v2 is live with no cold start, and v1 waits in staging as your rollback.

    🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.

    😟 THE PROBLEM

    Every release means a minute of errors while the app restarts.

    😊 THE SOLUTION

    Deploy to a staging slot, let it warm up, then swap.

    • Cold starts after deploy✓ Swap warms up first
    • Slow rollback✓ Swap back in seconds
    • Prod settings leak to test✓ Slot settings stay put
    🛠️ Solved with: Deployment slots

    Start with a question

    How does a theatre change the set without closing the curtain?

    Big theatres have a second stage behind the main one. While the audience watches act one, the crew builds act two back there, lights it, and checks every prop. Then the stages swap, and the audience sees the new scene with no wait. If something’s wrong, they can roll the old set straight back.

    A deployment slot is that second stage. You deploy the new version to staging, check it on its own URL, then swap it with production. App Service warms it up first, so users never see a half-built set.

    Explain it like I’m 10

    The technical explanation

    Create a slot

    Slots need a Standard plan (5 slots per app) or Premium v3 (20). Each slot is a real app with its own hostname, settings and deployments, running on the same plan’s instances.

    Portal: web app → Deployment → Deployment slots → + Add slot, enter a Name and choose Clone settings from (production, another slot or none).

    az webapp deployment slot create -g rg-admin-web -n app-contoso-shop01 --slot staging --configuration-source app-contoso-shop01
    az webapp deploy -g rg-admin-web -n app-contoso-shop01 --slot staging --src-path shop-v2.zip --type zip
    New-AzWebAppSlot -ResourceGroupName rg-admin-web -Name app-contoso-shop01 -Slot staging

    Slot settings: what stays and what moves

    In Settings → Environment variables, tick Deployment slot setting on values that describe the environment rather than the code: the production database, the payment gateway, ENVIRONMENT=Production.

    Swapped (moves with the code)Not swapped (stays with the slot)
    App settings and connection strings not marked as slot settingsApp settings and connection strings marked Deployment slot setting
    General settings such as framework version, 32/64-bit, web socketsCustom domain names, non-public certificates and TLS settings
    Handler mappings, path mappingsScale settings, Always On
    Public certificates, WebJobs contentIP restrictions (access restrictions), CORS
    VNet integration, managed identities, diagnostic settings
    Publishing endpoints and settings ending in _EXTENSION_VERSION
    az webapp config appsettings set -g rg-admin-web -n app-contoso-shop01 --slot-settings ENVIRONMENT=Production
    az webapp config appsettings set -g rg-admin-web -n app-contoso-shop01 --slot staging --slot-settings ENVIRONMENT=Staging

    Swap

    What happens, in order:

    1. App Service applies the target’s slot settings, connection strings and related config to the source instances, which restart.
    2. It waits for every instance to start and warm up (it calls the site root, or the paths in applicationInitialization).
    3. If everything’s healthy, it switches the routing, so the source’s warm instances now serve production. If not, the swap stops and production is untouched.

    Portal: Deployment slots → Swap, pick Source and Target, look at Config changes, optionally tick Perform swap with preview, then Start Swap.

    az webapp deployment slot swap -g rg-admin-web -n app-contoso-shop01 --slot staging --target-slot production
    # two-phase: preview, check, then complete (or reset)
    az webapp deployment slot swap -g rg-admin-web -n app-contoso-shop01 --slot staging --action preview
    az webapp deployment slot swap -g rg-admin-web -n app-contoso-shop01 --slot staging --action swap
    Switch-AzWebAppSlot -ResourceGroupName rg-admin-web -Name app-contoso-shop01 -SourceSlotName staging -DestinationSlotName production

    Roll back by swapping again: the previous version is still warm in staging.

    Auto swap and traffic routing

    • Auto swap (in the slot’s Configuration → General settings) swaps a slot into production after every deployment to it. It isn’t supported on Linux apps or Web App for Containers.
    • Traffic routing (the Traffic % column) sends a share of production users to another slot. A cookie (x-ms-routing-name) keeps each user on one slot. az webapp traffic-routing set --distribution staging=10.
    Architect level Slots share the plan, so watch the load

    Every slot runs on the plan’s instances. A staging slot under a heavy load test competes with production for CPU and memory. Keep load tests short, scale the plan out while you test, or run heavy tests against a copy on a separate plan. Also stop slots you aren’t using; a stopped slot doesn’t serve traffic but still exists on the plan.

    Real-world business scenario

    E-commerce

    Contoso Shop (fictional)

    The problem
    Each release restarted the shop and threw errors for about a minute. Once, a test payment endpoint went live because it was copied along with the code.
    What they used
    A staging slot on the Standard S1 plan, cloned from production. PAYMENT_API_URL, the order database connection string and ENVIRONMENT were marked as deployment slot settings. GitHub Actions deploys to staging, a smoke test runs against the staging URL, 10% of traffic goes there for an hour, then the pipeline swaps.
    Why that choice
    The swap warms up the new version before it takes traffic, slot settings keep test and production endpoints apart, and a second swap is the rollback plan.
    The result
    Releases moved from monthly to twice a week with no visible downtime, and one bad release was rolled back in under a minute.

    When to use it and when not to

    ✓ Use it when…

    • You release often and can't afford restart errors.
    • You want to test a build on real infrastructure with production-like settings first.
    • You want a one-click rollback for every release.

    ✕ Think twice when…

    • The plan is Basic or Free. Scale up to Standard first.
    • Staging needs its own capacity for heavy load tests. Use a separate plan.
    • You need separate subscriptions or regions per environment. Use separate apps.

    ↔ Alternatives to consider

    • Container Apps revisions with traffic splitting for container workloads.
    • Separate web apps per environment when dev, test and production must be fully isolated.
    • Azure Front Door to shift traffic between apps in different regions.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    Test yourself with exercises

    5 original practice questions in the AZ-104 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.

    Question 1

    Question 1 of 5

    A web app has a production slot and a staging slot. The connection string named OrdersDb must always point to the production database in the production slot, even after a swap.

    What should you do?

    Question 2

    Question 2 of 5

    A web app runs on an App Service plan in the Basic tier. You need to create a staging slot. What should you do first?

    Question 3

    Question 3 of 5

    You plan to swap a staging slot into production. You need to validate the staging slot while it uses the production slot settings, before traffic is switched. What should you use?

    Question 4

    Question 4 of 5 · Select 2

    Which two items remain with the production slot after you swap a staging slot into production? Each correct answer presents a complete solution.

    Question 5

    Question 5 of 5

    You need to send 10 percent of production users to a staging slot to test a new feature. Users must stay on the same slot for the rest of their session.

    What should you configure?

    Interview preparation

    Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.

    Beginner Why would you deploy to a staging slot instead of straight to production?

    Model answer

    So I can test the new version on its own URL first, and so the release doesn't cause downtime. When I swap, App Service warms the staging instances up before switching traffic. If something's wrong after the swap, I swap back and the old version is live again in seconds.

    Intermediate Which settings stay put during a swap?

    Model answer

    Anything I mark as a deployment slot setting, plus things that never swap: custom domain names, non-public certificates and TLS settings, scale settings, IP restrictions, Always On, CORS, diagnostic settings, VNet integration and managed identities. App settings and connection strings that aren't slot settings, handler mappings and the code itself all move with the swap.

    Experienced developer What actually happens during a swap?

    Model answer

    App Service applies the target slot's slot settings, connection strings and some config to the source slot's instances, which restarts them. It waits until every instance has restarted and warmed up, including any applicationInitialization paths I've configured. If that all succeeds, it switches the routing rules, so the source becomes production. If warm-up fails, the swap is cancelled and production never changed.

    Scenario You need to try a new checkout on 10% of real users before a full release. How?

    Model answer

    Deploy it to the staging slot, then set traffic routing on production to send 10% to staging, either in the Deployment slots blade or with az webapp traffic-routing set --distribution staging=10. Users get a cookie that keeps them on the same slot. If the numbers look good I swap; if not, I set staging back to 0%.

    Quick revision

    Key points

    • Slots need Standard (5 per app) or Premium v3 (20 per app). Basic and Free have none.
    • Slots run on the same plan, so they share its instances and scale settings.
    • A swap warms up the source first, then switches routing. Swap again to roll back.
    • Slot settings (sticky) stay with their slot. Domains, certificates, scale and IP restrictions never swap.
    • Swap with preview pauses after warm-up; traffic routing sends a percentage of users to a slot.

    Important terminology

    Deployment slot
    A separate live app with its own hostname that belongs to a web app and runs on the same App Service plan.
    Swap
    Exchanging the content and swappable settings of two slots after warming up the source, so the switch has no downtime.
    Slot setting
    An app setting or connection string marked Deployment slot setting, which stays with its slot during a swap.
    Swap with preview
    A two-phase swap that applies the target's settings to the source and stops, so you can check before completing or cancelling.
    Auto swap
    A slot option that swaps the slot into a target automatically after each deployment. Not supported on Linux apps or Web App for Containers.
    Traffic routing
    Sending a percentage of production traffic to another slot for testing in production. A cookie keeps each user on one slot.

    Common mistakes

    • Forgetting to mark production-only values (database, payment endpoint) as slot settings, so staging values reach production.
    • Trying to add slots on a Basic plan.
    • Expecting a slot to scale separately from production.

    Exam tips

    • "No downtime when releasing" = deploy to a slot and swap.
    • "Setting must not move during a swap" = mark it as a deployment slot setting.
    • "Validate with production settings before completing the swap" = swap with preview.

    Five quick revision questions

    1. 1.How many slots does Standard allow per app?Show

      Five (plus production).

    2. 2.Which tier is the lowest that supports slots?Show

      Standard.

    3. 3.Do custom domains swap?Show

      No, they stay with their slot.

    4. 4.How do you roll back a bad swap?Show

      Swap the slots again.

    5. 5.Which command swaps slots?Show

      az webapp deployment slot swap --slot staging --target-slot production.

    Official references

    Finished this lesson? Tick it off. Your progress is saved in this browser.

    Next up: Virtual Networks, Subnets and Public IP Addresses

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.