App Service Deployment Slots and Swaps
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.
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.
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
- Open Deployment → Deployment slots. The plan is Standard, so it allows 5 slots (Premium v3 allows 20). Select + Add slot.
- Name it staging and clone settings from production. A slot is a live app with its own hostname, running on the same plan.
- 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.
- Deploy v2 to staging and test it on its own URL. Optionally send it 10% of real traffic. Then select Swap.
- 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.
- 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.
🖱️ Drag to rotate · scroll or pinch to zoom
Staging slot, warm-up, swap
A deployment slot (Standard: 5, Premium v3: 20) is a live copy of the app. Deploy to staging, then swap: App Service warms staging up first, so users never hit a cold start. Slot settings stay with their slot.
🤔 What happens if…
Read this tour as text
- A registry feeds Container Instances. Azure Container Registry stores your private images. Container Instances runs them as a container group with the CPU and memory you set and a restart policy: Always, OnFailure or Never. It doesn’t scale itself, and only Premium registries can geo-replicate.
- Container Apps scale on HTTP traffic. Each replica gets an allowed CPU and memory pair (0.5 vCPU with 1 Gi here). An HTTP scale rule adds a replica per 50 concurrent requests, between min and max replicas. With min 0, a quiet app scales to zero.
- The plan is the VMs. An App Service plan is a set of VMs. Every app on the plan runs on every instance. Scale out adds instances (Basic: up to 3). Scale up moves to a bigger or richer tier, which also decides the features you get.
- Autoscale rules (Standard and up). On Standard or Premium, a rules-based autoscale setting watches a metric such as CPU Percentage and adds or removes instances between a minimum and maximum, with a cool-down so it doesn’t flap.
- Prove you own the domain. To map www.contoso-learn.com, App Service needs a TXT record asuid.www holding the app’s verification ID, plus a CNAME from www to the app (an A record for the root domain). Free tier can’t do custom domains.
- Certificate, HTTPS Only, TLS 1.2. A free App Service managed certificate (Basic and up, no wildcards, not exportable) is bound with SNI SSL. HTTPS Only redirects HTTP, and the minimum TLS version (1.2 by default) turns away old clients.
- Back up to your own storage. Automatic backups run hourly with no setup. Custom backups write files, configuration and linked databases (up to 10 GB) to a blob container you own, on demand or on a schedule with retention. Basic tier and up.
- Outbound and inbound are different switches. VNet integration is outbound: the app reaches private resources through a delegated subnet. Inbound is controlled by access restrictions (allow and deny rules by priority) or a private endpoint.
- Staging slot, warm-up, swap. A deployment slot (Standard: 5, Premium v3: 20) is a live copy of the app. Deploy to staging, then swap: App Service warms staging up first, so users never hit a cold start. Slot settings stay with their slot.
Contoso Shop runs on a small Basic plan. Black Friday is coming. Scale it by hand, find out what Basic can't do, then move to Standard for autoscale and a staging slot you can swap into production with no downtime.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 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
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 settings | App settings and connection strings marked Deployment slot setting |
| General settings such as framework version, 32/64-bit, web sockets | Custom domain names, non-public certificates and TLS settings |
| Handler mappings, path mappings | Scale settings, Always On |
| Public certificates, WebJobs content | IP 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:
- App Service applies the target’s slot settings, connection strings and related config to the source instances, which restart.
- It waits for every instance to start and warm up (it calls the site root, or the paths in
applicationInitialization). - 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
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.
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.
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.How many slots does Standard allow per app?Show
Five (plus production).
-
2.Which tier is the lowest that supports slots?Show
Standard.
-
3.Do custom domains swap?Show
No, they stay with their slot.
-
4.How do you roll back a bad swap?Show
Swap the slots again.
-
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
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.