Deployment Slots and Swap
Create staging slots for blue-green deployments, warm up a new release in the staging slot, and swap it into production with zero downtime.
Deployment Slots and Swap is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Are Deployment Slots?
Deployment slots are live, separate environments for an App Service web app, each with its own hostname (e.g., myapp-staging.azurewebsites.net). Slots share the same App Service plan and resources as the production slot but run independently. They enable blue-green deployments — you validate a new release in a staging slot, then swap it into production with zero downtime. Slots are available from the Standard tier and above.
Creating a Deployment Slot
Add a new deployment slot to your web app using the Azure portal or CLI. Each slot gets its own URL, application settings, and connection strings. You can create up to 5 slots on Standard, and up to 20 slots on Premium tier. Common slot names include staging, canary, hotfix, and integration, reflecting different stages of the release pipeline.
# Create a staging deployment slot
az webapp deployment slot create \
--name MyUniqueWebApp \
--resource-group MyRG \
--slot staging
# Deploy code to the staging slot
az webapp deploy \
--name MyUniqueWebApp \
--resource-group MyRG \
--slot staging \
--src-path app.zip
# The staging slot is live at:
# https://MyUniqueWebApp-staging.azurewebsites.netWarming Up the Staging Slot
Before swapping, it is critical to warm up the staging slot so the new version is fully initialised. A cold App Service instance serves the first requests slowly as the runtime initialises, which is unacceptable in production. Enable Auto Swap or manually send warm-up HTTP requests to the staging slot. App Service also supports a applicationInitialization configuration to define warm-up paths that must return 200 before the slot is considered ready.
# web.config snippet for warm-up (IIS/Windows)
# <system.webServer>
# <applicationInitialization>
# <add initializationPage='/health' hostName='MyUniqueWebApp-staging.azurewebsites.net'/>
# </applicationInitialization>
# </system.webServer>
# Or use a startup probe via the App Service health check
az webapp config set \
--name MyUniqueWebApp \
--resource-group MyRG \
--slot staging \
--generic-configurations '{"healthCheckPath": "/health"}'Swapping Slots
A swap atomically exchanges the staging and production slots. During a swap, App Service first routes traffic to the staging instances running the new code, waits for them to initialise, then reroutes all production traffic to the new instances and the old production instances become the new staging slot. This makes rollback trivial — just swap again to revert.
# Swap staging into production
az webapp deployment slot swap \
--name MyUniqueWebApp \
--resource-group MyRG \
--slot staging \
--target-slot production
# Rollback: swap production back to staging
az webapp deployment slot swap \
--name MyUniqueWebApp \
--resource-group MyRG \
--slot production \
--target-slot stagingSlot-Sticky vs. Non-Sticky Settings
Application settings can be marked as sticky (slot-specific) or non-sticky (swappable). Non-sticky settings travel with the deployment slot when you swap — so your staging database connection string follows the code into production. Sticky settings stay with the slot regardless of swaps — production always keeps its production database connection string. Mark settings as sticky using the 'deployment slot setting' checkbox or the CLI.
# Mark a setting as sticky (slot-specific) -- it won't swap
az webapp config appsettings set \
--name MyUniqueWebApp \
--resource-group MyRG \
--slot staging \
--slot-settings DATABASE_URL='postgresql://staging-db/...'
# Set a non-sticky setting (it WILL travel with a swap)
az webapp config appsettings set \
--name MyUniqueWebApp \
--resource-group MyRG \
--slot staging \
--settings FEATURE_FLAG_NEW_UI=trueTraffic Splitting for Canary Releases
App Service supports traffic splitting — routing a percentage of production traffic to a non-production slot without performing a full swap. This enables canary releases where you gradually shift traffic from 5% to 10% to 50% as you gain confidence in the new release, monitoring error rates at each step. Users who land on the canary slot receive a sticky cookie that keeps them on the same version for session consistency.
# Route 10% of traffic to the staging slot (canary)
az webapp traffic-routing set \
--name MyUniqueWebApp \
--resource-group MyRG \
--distribution staging=10
# View current traffic distribution
az webapp traffic-routing show \
--name MyUniqueWebApp \
--resource-group MyRG
# Reset all traffic to production
az webapp traffic-routing clear \
--name MyUniqueWebApp \
--resource-group MyRGAuto Swap
Auto Swap automatically swaps a staging slot into production whenever new code is deployed to it. It is ideal for CI/CD pipelines where you want every successful deployment to immediately go live. Auto Swap waits for the staging slot's HTTP requests to return 200 before completing the swap. Enable it per slot in the portal or CLI — but use it cautiously, as there is no manual approval gate between deploy and production.
# Enable Auto Swap for the staging slot
az webapp deployment slot auto-swap \
--name MyUniqueWebApp \
--resource-group MyRG \
--slot staging \
--auto-swap-slot production
# Disable Auto Swap
az webapp deployment slot auto-swap \
--name MyUniqueWebApp \
--resource-group MyRG \
--slot staging \
--disableDeployment Slot Best Practices
Follow these best practices for deployment slots: always validate in staging before swapping to production, use sticky settings to keep production database connections isolated from staging, run smoke tests against the staging slot URL after deployment, configure health check paths to ensure App Service won't complete the swap if the new version is unhealthy, and tag your deployments so you can trace which commit is live in each slot.
Slots in CI/CD Pipelines
In a typical CI/CD pipeline, the build stage compiles and tests the code, the deploy stage pushes the artifact to the staging slot, an integration test stage runs automated tests against the staging URL, and the swap stage swaps staging into production — optionally gated by a manual approval. This pattern is supported natively in both Azure Pipelines and GitHub Actions with the App Service deploy action.
# GitHub Actions step: deploy to staging slot
# - name: Deploy to Staging Slot
# uses: azure/webapps-deploy@v2
# with:
# app-name: MyUniqueWebApp
# slot-name: staging
# publish-profile: ${{ secrets.AZURE_STAGING_PUBLISH_PROFILE }}
#
# - name: Swap to Production
# uses: azure/CLI@v1
# with:
# inlineScript: |
# az webapp deployment slot swap \
# --name MyUniqueWebApp \
# --resource-group MyRG \
# --slot stagingMonitoring Swap Health
During and after a slot swap, monitor key metrics in Azure Monitor to confirm the new version is healthy. Watch for spikes in HTTP 5xx errors, average response time, and CPU/memory utilisation. Set up metric alerts that fire if error rates exceed a threshold — this gives you a signal to swap back quickly. Application Insights' smart detection can automatically alert you to anomalies after a deployment.
# Create an alert rule for HTTP 5xx errors post-swap
az monitor metrics alert create \
--name 'HighErrorRate' \
--resource-group MyRG \
--scopes '/subscriptions/.../providers/Microsoft.Web/sites/MyUniqueWebApp' \
--condition 'avg Http5xx > 10' \
--window-size 5m \
--evaluation-frequency 1m \
--action-group MyActionGroupSlots vs. Multiple Apps
Deployment slots are preferable to maintaining entirely separate App Service apps for staging and production because slots share the same plan (no extra cost), have one-click swap with rollback, support traffic splitting, and are managed under the same App Service resource. Use separate apps only when staging needs fundamentally different plan SKUs, isolation requirements, or completely separate billing.
Quick Check
Test your understanding of Microsoft Azure Fundamentals (AZ-900) concepts from this lesson.
Lesson Recap
In this lesson you learned: deployment slots provide isolated environments enabling blue-green deployments, slot-sticky settings keep environment-specific configuration (like database URLs) tied to the slot rather than the code, and traffic splitting enables canary releases by routing a percentage of production traffic to a new version. Next up we explore autoscaling and custom domains.
Frequently asked questions
Is the “Deployment Slots and Swap” lesson free?
Yes — the full text of “Deployment Slots and Swap” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.
What will I learn in “Deployment Slots and Swap”?
Create staging slots for blue-green deployments, warm up a new release in the staging slot, and swap it into production with zero downtime. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cloud & IT Cert Prep?
No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Deployment Slots and Swap” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cloud & IT Cert Prep lesson?
Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.