Minimizing Downtime with Load Balancing, Rolling Updates and Slots
This lesson explains how to keep capacity available during a release.
Learning outcomes
After completing this lesson, you will be able to:
- Explain health probes and connection draining.
- Configure the rolling strategy and its hooks.
- Explain what happens during a slot swap.
- Identify what swaps and what stays with a slot.
Load balancing and health probes
A load balancer spreads traffic across instances and sends requests only to healthy ones, as determined by a health probe. This enables an update without downtime: take an instance out of rotation, wait for its active requests to finish, which is known as connection draining, update it, verify it, and return it to service.
In Azure, Azure Load Balancer works at layer 4, whereas Azure Application Gateway and Azure Front Door work at layer 7, with Front Door providing global routing. Azure Traffic Manager routes at the DNS level. Any of these can move traffic between old and new versions, although DNS-based changes take effect only as cached records expire, so Traffic Manager is less suitable for an immediate switch.
Azure traffic services
Rolling deployments
A rolling deployment updates instances in small batches, while the rest continue serving. It needs no duplicate environment, so it costs little, but both versions run together during the release, and rollback requires rolling back in the same way.
In Azure Pipelines, the rolling strategy is supported for VM resources in an environment. maxParallel sets the size of each batch, either as a number or a percentage, and the lifecycle hooks run for each batch.
jobs:
- deployment: Web
environment:
name: production
resourceType: VirtualMachine
tags: web
strategy:
rolling:
maxParallel: 25%
preDeploy:
steps:
- script: ./remove-from-load-balancer.sh
deploy:
steps:
- script: ./install.sh
routeTraffic:
steps:
- script: ./add-to-load-balancer.sh
postRouteTraffic:
steps:
- script: ./smoke-test.sh
on:
failure:
steps:
- script: ./restore-previous.shThe lifecycle hooks run in this order: preDeploy, deploy, routeTraffic, postRouteTraffic, then on: failure or on: success. Artifacts download automatically only in the deploy hook. Virtual machine scale sets have their own rolling upgrade policy, and Kubernetes Deployments perform rolling updates with maxSurge and maxUnavailable.
Rolling deployment hooks
App Service deployment slots
A deployment slot is a live App Service app with its own host name, sharing the same App Service plan. Slots need the Standard, Premium or Isolated tier. The Standard tier allows five slots, and they carry no additional charge, since they use the plan's capacity. A team deploys to a staging slot, verifies it, and then swaps it with production.
What happens during a swap
A swap is safe because it prepares the target first. App Service applies production settings to the staging instances, restarts them, and waits for them to warm up, optionally calling a custom warm-up path. When every instance is ready, routing rules switch, so users move to warmed instances, and in-flight requests are not dropped. The previous production content is now in staging, so swapping again is an immediate rollback.
What swaps and what stays
Not everything moves with the content, and this is a popular exam question. The following table lists the main items. A setting marked as a deployment slot setting stays with its slot, which is how a slot keeps its own connection string.
| Swapped with the content | Stays with the slot |
|---|---|
| Language and framework settings | Custom domain names |
| App settings not marked as slot settings | Non-public certificates and TLS settings |
| Connection strings not marked as slot settings | Scale settings |
| Handler mappings and public certificates | Always On, IP restrictions and CORS |
| WebJobs content | Managed identities and virtual network integration |
| Mounted storage | Publishing endpoints and diagnostic log settings |
Swap with preview
Swap with preview runs in two phases. The first applies target settings to the source slot and pauses, so that the team can verify the application with production settings. The team then completes or cancels the swap. It cannot be used when site authentication is enabled in either slot.
Auto swap and traffic routing
Auto swap swaps into production automatically after a push to a slot, once it has warmed up. It is not supported on Linux web apps or Web App for Containers. Traffic routing sends a percentage of production traffic to a slot, which provides a simple canary, and each routed client remains pinned to that slot for up to an hour or until cookies are deleted.
- task: AzureWebApp@1
inputs:
azureSubscription: sc-azure-prod
appName: contoso-web
deployToSlotOrASE: true
resourceGroupName: rg-web
slotName: staging
package: $(Pipeline.Workspace)/web
- task: AzureAppServiceManage@0
inputs:
azureSubscription: sc-azure-prod
Action: Swap Slots
WebAppName: contoso-web
ResourceGroupName: rg-web
SourceSlot: stagingThe following diagram compares an ordinary app setting with a deployment slot setting during a slot swap.

Does it swap?
Settings during a swap
A staging slot uses a test database. After a swap, production begins using the test database. What should have been done?
The connection string should have been marked as a deployment slot setting, on both slots. Without that mark, the setting moves with the content, so the staging value reached production. Using a separate App Service plan would not change this behaviour, and neither would swap with preview by itself, although a preview might have revealed the problem before completion.
Does a custom domain move with the content during a slot swap?
Show answer
No. Custom domain names stay with the slot, along with scale settings and non-public certificates.
Exam Tips
Remember for the exam
- Health probes and connection draining allow instances to be updated safely.
- The rolling strategy in Azure Pipelines applies to VM resources.
- Hook order: preDeploy, deploy, routeTraffic, postRouteTraffic, on failure or success.
- A swap warms instances first; swapping again rolls back.
- Mark a value as a deployment slot setting to keep it with the slot.