Virtual Machine Scale Sets, Availability and Autoscale: Flexible Orchestration, Health Probes and Rolling Upgrades
The Idea
One VM can fail or get overloaded. A Virtual Machine Scale Set (VMSS) creates and manages a group of VMs from one model, adds or removes VMs with load, replaces unhealthy ones and updates them gradually.
Orchestration Modes
| Mode | Description | Use |
|---|---|---|
| Flexible (recommended for new work) | Mix VM sizes, add existing VMs, spread across zones and fault domains, more control per VM | Most workloads |
| Uniform | All VMs identical, managed strictly from the model | Large stateless fleets and older designs |
Create a Scale Set Behind a Load Balancer
bash
az vmss create -g rg-demo -n vmss-web --image Ubuntu2204 --vm-sku Standard_B2s --instance-count 3 \
--orchestration-mode Flexible --zones 1 2 3 --vnet-name vnet-app --subnet web \
--lb lb-web --upgrade-policy-mode Automatic --admin-username azureuser --generate-ssh-keys \
--custom-data cloud-init.yaml
az vmss list-instances -g rg-demo -n vmss-web -o table
az vmss scale -g rg-demo -n vmss-web --new-capacity 5
Autoscale
- Metric rules: scale out when average CPU is above 70 percent for 10 minutes, scale in when below 30 percent for 10 minutes
- Schedule rules: more instances on weekdays
- Set minimum, maximum and default counts
- Always pair scale out with a scale in rule with a gap (avoid flapping)
- Use a cooldown so new VMs can start before the next decision
- Other metrics: memory (with agent), queue length, request count
bash
az monitor autoscale create -g rg-demo --resource vmss-web --resource-type Microsoft.Compute/virtualMachineScaleSets \
--name autoscale-web --min-count 3 --max-count 10 --count 3
az monitor autoscale rule create -g rg-demo --autoscale-name autoscale-web --condition "Percentage CPU > 70 avg 10m" --scale out 2
az monitor autoscale rule create -g rg-demo --autoscale-name autoscale-web --condition "Percentage CPU < 30 avg 10m" --scale in 1
Health and Automatic Repairs
- Add the Application Health extension or use load balancer probes to report health
- Turn on automatic instance repairs so unhealthy instances are replaced (with a grace period)
- Use
/healthstyle endpoints that check dependencies lightly
Updating the Fleet
| Policy | Behavior |
|---|---|
| Manual | You update each instance |
| Automatic | All at once (can cause downtime) |
| Rolling | Batches with health checks and pause on failure (best for production) |
- Roll out a new image version from the Azure Compute Gallery by updating the scale set model
- Enable automatic OS image upgrades for patching with rolling behavior
Mix and Save
- Spot priority with eviction policy for batch capacity
- Mix On-Demand and Spot with Flexible mode and
priorityMixPolicy - Reserved instances for the base capacity
Design Tips
Stateless wins Keep instances stateless. Store sessions in Azure Cache for Redis, files in Blob Storage and data in a database, so any instance can be replaced at any time.
Practice
- Create a Flexible scale set across three zones
- Add CPU autoscale rules and generate load with
stress - Stop the web server on one VM and watch automatic repair replace it
- Roll out a new custom-data version with a rolling upgrade
Conclusion
Scale sets run many identical VMs with zones, autoscale, health-based repairs and rolling upgrades. Use Flexible mode, pair scale-out with scale-in rules and design instances to be stateless.
Quick Summary: idea; modes; create; autoscale; health; updates; savings; tips.

