AZ-104Chapter 98 of 168Objective 3.2

App Service Deployment Slots and Swapping

This chapter covers Azure App Service deployment slots and swapping, a critical feature for zero-downtime deployments and traffic routing. For the AZ-104 exam, approximately 10-15% of Compute questions touch on deployment slots, slot swapping, and traffic routing. Understanding the mechanics of slot swapping, auto-swap, and traffic routing is essential for passing the exam and for real-world Azure administration.

25 min read
Intermediate
Updated May 31, 2026

Blue-Green Deployment with a Light Switch

Imagine a theater with two identical stages: Stage A (production) and Stage B (staging). The audience sees only Stage A. You want to change the set on Stage B without disturbing the current show. You prepare the new set on Stage B, test it with a small invited audience (slot warm-up), and ensure everything works. When ready, you flip a switch that instantly swaps which stage the audience sees — now they see Stage B, and Stage A becomes the new staging area. If the new show has problems, you flip the switch back to Stage A (immediate rollback). The switch is not a simple toggle; it also transfers lighting cues and sound settings (configuration and connection strings) to ensure the new stage behaves exactly like the old one. This is how deployment slots work: you have a production slot and a staging slot, and swapping them is like flipping that switch, but with careful preparation to avoid a bad show.

How It Actually Works

What Are Deployment Slots?

Deployment slots are live, fully functional instances of your App Service app that run in the same App Service Plan but with their own hostnames, settings, and code. Each slot is essentially a separate deployment environment that shares the same underlying compute resources. The primary slot is called the 'production' slot, and you can create additional slots (e.g., 'staging', 'testing') for testing new versions of your app before making them live.

Why Use Deployment Slots?

The main purpose of deployment slots is to enable zero-downtime deployments. By deploying your new code to a staging slot and then swapping it with the production slot, you avoid any downtime during deployment. Additionally, you can route a percentage of traffic to a specific slot for A/B testing or canary releases. The exam focuses on:

Creating and managing slots

Swapping slots (manual and auto-swap)

Slot-specific settings (sticky vs. non-sticky)

Traffic routing

Rollback scenarios

How Slot Swapping Works Internally

When you initiate a swap between two slots (e.g., staging to production), Azure performs the following steps:

1.

Warm-up Phase: Azure applies the target slot's app settings and connection strings to the source slot. This ensures that the source slot (e.g., staging) has the same configuration as the target (production) before it receives live traffic. The warm-up phase also triggers the application startup (e.g., /bin/startup) and any configured warm-up paths.

2.

Routing Switch: Azure updates the Azure Front Door or Traffic Manager routing rules to direct user traffic to the source slot. This switch is instantaneous and does not cause downtime because both slots are already running.

3.

Post-Swap Cleanup: After the swap, the previous production slot (now the staging slot) may have settings from the old production environment. Azure can optionally apply the original settings to the new staging slot to keep it consistent for future swaps.

Key Components and Defaults

Number of Slots: You can have up to 5 slots per App Service app (including the production slot). Additional slots may be available in Premium plans.

Slot Names: Slot names must be unique within the app and can be up to 60 characters, alphanumeric and hyphens.

Slot-specific Settings: Settings can be marked as 'sticky' (slot-specific) or 'non-sticky' (global). Sticky settings remain with the slot even after a swap. Common sticky settings include connection strings, app settings, and custom domain bindings.

Auto-swap: You can enable auto-swap on a slot so that whenever you deploy a new version to that slot, Azure automatically swaps it with the production slot after the deployment completes. Auto-swap is useful for continuous deployment pipelines.

Traffic Routing: You can route a percentage of incoming traffic to a specific slot without swapping. This is done via the Azure Portal or CLI by setting the trafficWeight property on a slot. The weight is a percentage from 0 to 100, and the sum across all slots must be 100. The exam tests that traffic routing does not affect sticky settings — the slot retains its own settings.

Configuration and Verification Commands

Using Azure CLI:

# Create a new slot
az webapp deployment slot create --name MyApp --resource-group MyRG --slot staging

# List slots
az webapp deployment slot list --name MyApp --resource-group MyRG --output table

# Swap slots
az webapp deployment slot swap --name MyApp --resource-group MyRG --slot staging --target-slot production

# Configure auto-swap
az webapp deployment slot auto-swap --name MyApp --resource-group MyRG --slot staging

# Set sticky settings (slot-specific)
az webapp config appsettings set --name MyApp --resource-group MyRG --slot staging --settings MySetting=MyValue --slot-settings

# Route traffic to a slot
az webapp traffic-routing set --name MyApp --resource-group MyRG --distribution staging=10 production=90

Using Azure PowerShell:

# Create a slot
New-AzWebAppSlot -ResourceGroupName MyRG -Name MyApp -Slot staging

# Swap slots
Switch-AzWebAppSlot -ResourceGroupName MyRG -Name MyApp -SourceSlotName staging -DestinationSlotName production

# Set sticky settings
Set-AzWebAppSlot -ResourceGroupName MyRG -Name MyApp -Slot staging -AppSettings @{"MySetting"="MyValue"} -SlotSettings @{"MyStickySetting"="StickyValue"}

How It Interacts with Related Technologies

App Service Plan: Slots share the same App Service Plan, so they compete for resources. If the plan is scaled out to multiple instances, each slot runs on all instances.

Custom Domains: Custom domains can be assigned to any slot, but typically only the production slot has a custom domain. After a swap, the custom domain remains with the slot unless you change it.

SSL/TLS Certificates: Certificates bound to a slot are sticky — they stay with the slot after a swap. This is important for slot-specific domain bindings.

Continuous Deployment: Deployment slots integrate with CI/CD pipelines. You can deploy to a staging slot, run tests, then swap. Auto-swap can be triggered after a successful deployment.

Azure Front Door / Traffic Manager: These services can route traffic to specific slots based on rules. Slot swapping updates the backend pool automatically if configured.

Common Exam Scenarios

Rollback: If a swap introduces issues, you can swap back immediately. The previous production slot still has the old code and settings, so swapping back restores the original state.

Slot-specific settings: The exam loves to test that connection strings marked as slot settings are not swapped. For example, a staging slot might connect to a test database, while production connects to the live database. After a swap, the staging slot retains its test database connection string.

Auto-swap and deployment: Auto-swap is triggered after a deployment to the slot. If the deployment fails, the swap does not occur. This is a common exam point.

Traffic routing and warm-up: When routing traffic to a slot, Azure does not automatically warm up the slot. You must ensure the slot is ready to handle traffic. Warm-up can be configured via the WEBSITE_WARMUP_PATH app setting.

Limitations and Edge Cases

Swap with Preview: This feature allows you to validate the swap before it completes. It is available in Premium plans. The exam may ask about this as an alternative to manual swap.

Multiple slots: You can have multiple staging slots for different environments (e.g., dev, test, staging). Swapping between non-production slots is allowed.

Slot creation: Slots cannot be created in the Free or Shared tiers. They require at least a Basic plan.

Slot swapping and scaling: If you scale the App Service Plan, all slots are affected equally. There is no per-slot scaling.

Summary of Exam-Critical Values

Maximum slots: 5 (including production) for most tiers, more for Premium.

Sticky settings: Connection strings, app settings, custom domains, certificates.

Non-sticky settings: Framework version, virtual application, etc.

Auto-swap trigger: Successful deployment to the slot.

Traffic routing: Percentage-based, does not affect sticky settings.

Warm-up: Use WEBSITE_WARMUP_PATH to specify a warm-up path.

Swap with Preview: Available in Premium plans.

Walk-Through

1

Create a Staging Slot

In the Azure Portal, navigate to your App Service app. Under 'Deployment' select 'Deployment slots'. Click 'Add Slot' and give it a name like 'staging'. The slot inherits the app settings and connection strings from the production slot initially, but you can mark some as slot-specific later. The slot runs on the same App Service Plan, so it uses the same compute resources. Once created, the slot has its own URL (e.g., myapp-staging.azurewebsites.net). You can deploy code to this slot via any deployment method (FTP, Git, CI/CD).

2

Configure Slot-Specific Settings

In the staging slot's Configuration blade, add app settings or connection strings that should remain with the slot after a swap. For example, set a connection string to point to a test database. Mark these settings as 'slot settings' (sticky) by checking the 'deployment slot setting' checkbox. This ensures that when you swap, these settings stay with the staging slot (now the new production slot) and the old production slot's settings remain with it. Non-sticky settings (like .NET Framework version) are swapped with the slot.

3

Deploy Code to Staging

Deploy your new application version to the staging slot. This can be done via Visual Studio, Azure DevOps, GitHub Actions, or manual upload. The deployment does not affect the production slot, so users continue to use the old version without interruption. After deployment, you can test the staging slot by accessing its URL. Verify that the application works correctly with the staging settings.

4

Initiate Slot Swap

In the Azure Portal, go to the production slot's 'Deployment slots' blade and click 'Swap'. Select the source slot (staging) and target slot (production). You can also choose a 'Swap with preview' option (Premium plans) that allows you to validate the swap before it completes. The swap process warms up the staging slot with production settings, then switches the routing. The entire operation takes a few seconds to minutes depending on the app's warm-up time.

5

Validate and Rollback if Needed

After the swap, the staging slot becomes the new production slot and vice versa. Test the production site to ensure everything works. If issues arise, you can immediately perform another swap to rollback. The old production slot (now staging) still has the previous code and settings, so swapping back restores the original state. Rollback is instantaneous and does not require re-deployment.

What This Looks Like on the Job

Scenario 1: E-commerce Platform with Frequent Deployments

A large e-commerce company deploys updates multiple times per day. They use a staging slot for each deployment. The production slot connects to a live database, while the staging slot connects to a replica database. They mark the database connection string as a slot setting to prevent accidental data corruption. After deploying to staging and running automated tests, they swap. If the swap causes errors (e.g., a broken checkout page), they swap back immediately. This setup allows zero-downtime deployments and quick rollbacks. In production, they also route 5% of traffic to the staging slot for canary testing before full swap. This is configured via the 'Traffic Routing' blade. They monitor error rates and performance metrics to decide when to perform the full swap.

Scenario 2: SaaS Application with Multi-Tenant Configurations

A SaaS provider hosts multiple tenants in a single App Service app, using slot-specific settings to differentiate environments. They have a 'dev' slot, 'test' slot, and 'staging' slot. Each slot has its own set of connection strings and app settings that are sticky. They use auto-swap for the staging slot: whenever a new build is deployed to staging via CI/CD, Azure automatically swaps it with production after a successful deployment. This eliminates manual intervention. They also use the WEBSITE_WARMUP_PATH setting to ensure the application's cache is warmed up before receiving traffic. A common misconfiguration is forgetting to mark the tenant-specific settings as sticky, causing the wrong tenant to receive production data after a swap. They learned this the hard way when a swap caused a tenant to see another tenant's data.

Scenario 3: Government Agency with Strict Compliance

A government agency requires that all changes go through a formal approval process. They use 'Swap with preview' to allow compliance officers to validate the staging slot before the swap completes. The preview phase shows the staging slot with production settings (but no traffic), allowing them to check functionality. After approval, the swap completes. They also have a custom domain bound to the production slot, and they ensure the SSL certificate is also slot-specific. During an audit, they demonstrated that no downtime occurred during deployments. Misconfiguration of slot settings once caused a security breach where a test API key was exposed in production; they now enforce that all sensitive settings are marked as slot settings.

How AZ-104 Actually Tests This

What AZ-104 Tests on Deployment Slots

The AZ-104 exam objectives under 'Configure and manage virtual networking' include deployment slots as part of 'Configure App Service plans and apps' (objective 3.2). Specifically, you must be able to:

Create and manage deployment slots

Perform slot swaps

Configure auto-swap

Manage slot-specific settings (sticky vs. non-sticky)

Route traffic to slots

Common Wrong Answers and Why Candidates Choose Them

1.

'Slot swapping causes downtime because the app restarts.' This is false. Slot swapping does not restart the app; it only switches routing. The warm-up phase may trigger a startup if the app has a startup path, but the app is already running. Candidates confuse slot swapping with a regular deployment that restarts the app.

2.

'All settings are swapped between slots.' This is false. Settings marked as 'slot settings' (sticky) remain with the slot. Candidates often overlook the checkboxes in the portal and assume everything moves.

3.

'Traffic routing changes the slot settings.' This is false. Traffic routing only directs a percentage of requests to a slot; it does not alter the slot's settings. Candidates think that routing traffic to a slot somehow merges settings.

4.

'Auto-swap occurs immediately after deployment to any slot.' This is false. Auto-swap is configured on a specific slot and only triggers when that slot receives a deployment. Candidates think it applies to all slots.

Specific Numbers and Terms Appearing on the Exam

Maximum 5 slots per app (including production) for most tiers.

Slot names: up to 60 characters, alphanumeric and hyphens.

Sticky settings: connection strings, app settings, custom domains, certificates.

Non-sticky settings: framework version, virtual application, etc.

Auto-swap: enabled on a slot, triggered by a successful deployment.

Traffic routing: percentage from 0-100, sum must be 100.

Swap with preview: available in Premium plans.

Edge Cases and Exceptions

Free/Shared tiers: No deployment slots allowed.

Swap with preview: Only in Premium plans; other tiers use direct swap.

Slot creation: Requires at least a Basic plan.

Multiple slots: You can create up to 5 slots, but if you need more, you must upgrade to an Isolated plan.

Slot swap and scaling: Scaling the plan scales all slots equally.

How to Eliminate Wrong Answers Using the Underlying Mechanism

When you see a question about slot swapping, remember the mechanism: swapping changes routing, not code or settings. If a question says 'settings will be lost' or 'app will restart', it's wrong. If it says 'sticky settings remain', it's correct. For traffic routing, remember that it's a percentage-based distribution and does not affect slot settings. For auto-swap, look for the condition 'after a successful deployment to the slot with auto-swap enabled'.

Key Takeaways

Deployment slots allow zero-downtime deployments by swapping routing between slots.

You can have up to 5 slots per app (including production) in most tiers.

Sticky settings (slot settings) remain with the slot after a swap; non-sticky settings are swapped.

Auto-swap triggers after a successful deployment to the configured slot.

Traffic routing distributes a percentage of requests to a slot without swapping.

Slot creation requires at least a Basic App Service plan.

Swap with preview is available only in Premium plans for validation before final swap.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Manual Swap

Requires manual initiation via portal, CLI, or API.

Allows testing in staging before swapping.

Gives full control over when the swap occurs.

Commonly used for production deployments with manual approval.

No automatic trigger; must be done explicitly.

Auto-Swap

Automatically swaps after a successful deployment to a specific slot.

Eliminates manual intervention, ideal for CI/CD pipelines.

Reduces human error but offers less control.

Configured on a slot; can be enabled or disabled.

Swap occurs immediately after deployment succeeds.

Watch Out for These

Mistake

Slot swapping causes application downtime.

Correct

Slot swapping is zero-downtime because both slots run simultaneously. The swap only changes routing, not the application state. The warm-up phase ensures the new slot is ready before receiving traffic.

Mistake

All app settings are transferred during a swap.

Correct

Only non-sticky settings are swapped. Sticky settings (marked as slot settings) remain with their original slot. This is crucial for connection strings pointing to different databases.

Mistake

Traffic routing to a slot changes the slot's configuration.

Correct

Traffic routing only directs a percentage of requests to a slot; it does not modify the slot's settings. The slot retains its own sticky and non-sticky settings.

Mistake

Auto-swap works for any slot after any deployment.

Correct

Auto-swap is configured on a specific slot and only triggers when that slot receives a deployment. It does not apply to other slots automatically.

Mistake

You can create deployment slots in any App Service plan tier.

Correct

Deployment slots are only available in Basic, Standard, Premium, and Isolated tiers. Free and Shared tiers do not support slots.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between a deployment slot and a separate App Service app?

A deployment slot is a separate environment within the same App Service app, sharing the same App Service Plan and compute resources. A separate App Service app would have its own plan and resources, costing more. Slots are designed for staging and testing, while separate apps are for different applications entirely.

Can I route 100% of traffic to a staging slot without swapping?

Yes, you can set the traffic weight of the staging slot to 100% and the production slot to 0%. This effectively sends all traffic to staging. However, the staging slot retains its own settings (e.g., test database), which may not be suitable for production. Use this for testing with real traffic.

What happens to custom domains during a swap?

Custom domains are sticky settings. If a custom domain is bound to the production slot, it stays with the production slot even after a swap. To have the domain follow the app, you must reassign it after the swap or use a Traffic Manager/Front Door in front.

Does auto-swap work with deployment from GitHub Actions?

Yes, auto-swap works with any deployment method that updates the slot's code. For GitHub Actions, you can deploy to the staging slot, and if auto-swap is enabled, Azure will swap after the deployment succeeds.

Can I have more than 5 slots?

The default limit is 5 slots (including production). However, in Isolated plans, you can request an increase. For most scenarios, 5 slots are sufficient.

How do I rollback a swap?

Simply perform another swap between the same slots. The old production slot (now staging) still has the previous code and settings, so swapping back restores the original state. This is immediate.

What is the warm-up phase during swap?

Before the routing switch, Azure applies the target slot's settings to the source slot and triggers the application's startup path (if configured). This ensures the app is ready to handle requests. You can customize the warm-up path using the WEBSITE_WARMUP_PATH app setting.

Terms Worth Knowing

Ready to put this to the test?

You've just covered App Service Deployment Slots and Swapping — now see how well it sticks with free AZ-104 practice questions. Full explanations included, no account needed.

Done with this chapter?