Overview and What You Will Learn
A deployment slot is a separate, live copy of an App Service app with its own URL, and a swap exchanges the staging slot with production without taking the app offline. In this lab you will deploy version 1 to production, deploy version 2 to a staging slot, test it on the staging URL, swap it into production, and swap back to roll it back.
- Creating an App Service Plan that supports slots
- Creating a staging slot that copies production's configuration
- Marking app settings as slot-specific so they stay put during a swap
- Swapping staging into production and reversing the swap
- Warming up a slot before it takes traffic
Why This Matters in Production
Slots separate deploying a release from releasing it, so customers never see a version you have not tested on a real URL. Imagine a team at a company like Swiggy that deploys straight to a single production app and finds a bug affecting live orders minutes later, then must redeploy the old build under pressure. With a staging slot, the new version is tested first, and rolling back is a second swap instead of a redeploy.
Core Principles
A swap applies the target slot's settings to the staging slot, restarts and warms it up, and only then redirects production traffic to it. The previous production version lands in the staging slot, so a second swap restores it within moments. Slots share the App Service Plan's compute, so they add no separate hosting charge.
own live URL]:::soft STG -->|test and warm up| SWP{Swap}:::warn SWP --> PRD[Production slot
now serves v2]:::ok SWP --> OLD[Staging slot
now holds v1]:::soft OLD -.->|swap back| PRD classDef tool fill:#326CE5,color:#FFFFFF classDef soft fill:#DBEAFE,color:#1E293B classDef warn fill:#FFEDD5,color:#1E293B classDef ok fill:#10B981,color:#FFFFFF
RememberDeployment slots need the Standard (S1) tier or higher. Free, Shared and Basic plans do not support them, and S1 allows up to five slots including production.
Detailed Step-by-Step Practical Lab
- Create a resource group, an App Service Plan, and a web app:
az group create --name rg-slots-lab-central --location centralindia az appservice plan create \ --name asp-slots-lab \ --resource-group rg-slots-lab-central \ --sku S1 \ --is-linux az webapp create \ --resource-group rg-slots-lab-central \ --plan asp-slots-lab \ --name inventory-app-rahul \ --runtime "NODE:20-lts"- Build two tiny Node.js versions of the app. Each one reports its version and the value of an
APP_ENVsetting:
mkdir inventory-v1 inventory-v2 cat > inventory-v1/server.js << 'EOF'require('http').createServer((req, res) => res.end('inventory v1 env=' + process.env.APP_ENV + '\n')).listen(process.env.PORT || 8080);EOF cat > inventory-v2/server.js << 'EOF'require('http').createServer((req, res) => res.end('inventory v2 env=' + process.env.APP_ENV + '\n')).listen(process.env.PORT || 8080);EOF for v in v1 v2; do (cd inventory-$v && npm init -y > /dev/null && npm pkg set scripts.start="node server.js" && zip -qr ../inventory-app-$v.zip .)done- Deploy version 1 to production and mark its
APP_ENVas a slot-specific setting:
az webapp deployment source config-zip \ --resource-group rg-slots-lab-central \ --name inventory-app-rahul \ --src ./inventory-app-v1.zip az webapp config appsettings set \ --resource-group rg-slots-lab-central \ --name inventory-app-rahul \ --slot-settings APP_ENV=production- Create the staging slot as a copy of production's configuration, and give it its own slot-specific setting:
az webapp deployment slot create \ --resource-group rg-slots-lab-central \ --name inventory-app-rahul \ --slot staging \ --configuration-source inventory-app-rahul az webapp config appsettings set \ --resource-group rg-slots-lab-central \ --name inventory-app-rahul \ --slot staging \ --slot-settings APP_ENV=staging- Deploy version 2 to the staging slot only. Production keeps serving version 1:
az webapp deployment source config-zip \ --resource-group rg-slots-lab-central \ --name inventory-app-rahul \ --slot staging \ --src ./inventory-app-v2.zip- Test both URLs. Look up the host names rather than guessing them, since newer apps can have a generated suffix:
PROD_HOST=$(az webapp show --resource-group rg-slots-lab-central \ --name inventory-app-rahul --query defaultHostName --output tsv)STG_HOST=$(az webapp deployment slot list --resource-group rg-slots-lab-central \ --name inventory-app-rahul --query "[0].defaultHostName" --output tsv) curl "https://$PROD_HOST" curl "https://$STG_HOST"# Expected: inventory v2 env=staging- Send a few requests to the staging slot so the app has finished starting before it takes real traffic, then swap staging into production:
for i in 1 2 3 4 5; do curl -s "https://$STG_HOST" > /dev/null; done az webapp deployment slot swap \ --resource-group rg-slots-lab-central \ --name inventory-app-rahul \ --slot staging \ --target-slot production- Confirm production now runs version 2 and kept its own
APP_ENVvalue, because that setting is slot-specific and did not move with the code:
curl "https://$PROD_HOST"# Expected: inventory v2 env=production- Roll back by swapping again. Production returns to version 1 within moments:
az webapp deployment slot swap \ --resource-group rg-slots-lab-central \ --name inventory-app-rahul \ --slot staging \ --target-slot production curl "https://$PROD_HOST"# Expected: inventory v1 env=production- Clean up. The S1 plan bills by the hour, so delete it promptly:
az group delete --name rg-slots-lab-central --yes --no-waitProduction Best Practices & Common Pitfalls
Common MistakeDeploying new code straight to the production slot with no staging step, then finding a critical bug only after customers are affected. A staging slot adds no extra hosting cost and gives you a real live environment before anyone sees the release.
TipA swap exchanges slots in moments and can be reversed by swapping again, which makes it one of the lowest-risk ways to release. For extra caution, use
--action previewto apply production settings to staging and test with them before completing the swap.
- Mark environment-specific settings as slot-specific. Connection strings and API keys that differ per environment must be flagged as slot settings, or they travel with the code and point production at staging resources.
- Warm up before swapping. Hit the slot's key pages first, or set
WEBSITE_SWAP_WARMUP_PING_PATHso App Service pings a path before routing traffic, otherwise customers hit cold starts. - Remember that slots share one plan. A heavy test on staging consumes the same CPU and memory as production, so avoid load testing in a slot on a small plan.
- Try canary traffic when you want less risk.
az webapp traffic-routing set --distribution staging=10sends 10 percent of production traffic to staging, so a bad release reaches only a few users. - Keep the previous version in the slot after a swap. It is your rollback, so do not redeploy over it until the new release has proven stable.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
az webapp deployment slot create |
Create a new deployment slot |
az webapp deployment slot swap |
Swap two slots, promoting one to production |
az webapp deployment slot list |
List all slots for a web app |
az webapp deployment source config-zip |
Deploy a zip package to a slot |
az webapp config appsettings set --slot-settings |
Set a slot-specific app setting |
az webapp traffic-routing set |
Send a share of production traffic to a slot |