3.2AZ-104Intermediate
Est: ~15 mins•Verified: 2026-08
Azure VM Scale Sets (VMSS) & Azure App Services
Configure elastic compute with Virtual Machine Scale Sets (VMSS) autoscale rules, upgrade policies (Automatic, Rolling, Manual), and deploy high-availability web applications using Azure App Service plans and deployment slots.
Tags:#Azure#Compute#VMSS#Scale Sets#Autoscale#App Services#Deployment Slots#AZ-104
01
Overview
Enterprise compute workloads require dynamic elasticity to handle unpredictable traffic spikes while minimizing idle cloud costs. In Microsoft Azure, two primary compute services fulfill this requirement:
- Virtual Machine Scale Sets (VMSS): Manage and configure a collection of identical, auto-scaling VMs across fault domains and availability zones.
- Autoscale Engine: Automatically adjusts instance counts based on metric rules (CPU %, memory %, queue depth) or predictable schedules (time-based scaling).
- VMSS Upgrade Policies: Dictates how OS image and configuration updates propagate to VM instances:
- Automatic: Instantly updates all instances simultaneously with zero guarantees on capacity (potential downtime).
- Rolling: Batches updates in staggered waves, validating health probes before advancing to the next batch.
- Manual: Administrator explicitly triggers the upgrade per instance (
Update-AzVmssInstance).
- Azure App Service: Platform-as-a-Service (PaaS) hosting web applications and REST APIs without managing underlying OS, with zero-downtime Deployment Slots (Staging to Production swap).
---
02
When to Use: VMSS vs Azure App Services
| Capability | VMSS (IaaS) | Azure App Service (PaaS) |
|---|---|---|
| Operating System Control | Full root/admin access to Windows Server or Linux. | Fully managed by Microsoft; no OS patching or administrative access. |
| Networking & Custom Agents | Full custom VNet integration, custom drivers, legacy COM components. | Easy VNet integration, hybrid connections, serverless integration. |
| Scaling Mechanism | Metric/schedule-driven VM instance provisioning (takes 3–7 mins). | Metric-driven container/worker scaling (takes seconds to minutes). |
| Deployment Mechanism | Custom Script Extensions, Golden Images, Cloud-init. | Git, CI/CD pipelines, Docker containers, zero-downtime slot swapping. |
---
03
Prerequisites
Administrator Permissions:
- Virtual Machine Contributor and Network Contributor on the target resource group (for VMSS).
- Website Contributor on the App Service Plan and App Service resource.
---
04
Portal Path
TEXT
Azure Portal (https://portal.azure.com)
├── Virtual machine scale sets > [Your VMSS]
│ ├── Scaling (Configure Autoscale metric conditions: scale-out / scale-in)
│ ├── Operating system (Select base image & upgrade policy: Automatic/Rolling/Manual)
│ └── Instances (Inspect instance health, manually re-image or upgrade)
└── App Services > [Your Web App]
├── Scale up (Change App Service Plan tier: Basic, Standard, Premium)
├── Scale out (Configure Autoscale rules)
└── Deployment slots (Add staging slot and perform Swap)---
05
Step-by-Step Implementation
Step 1: Deploy a VM Scale Set with Flexible Orchestration
- Navigate to Virtual machine scale sets > + Create.
- Configure:
- Orchestration mode: Flexible (recommended for mixed VM types and availability zone balancing).
- Fault domain count:
1(for zone-redundant) or2–3(for single zone). - Image: Windows Server 2022 Datacenter or Ubuntu Server 22.04 LTS.
- Instance count: Set minimum
2, default2, maximum10.
Step 2: Configure Autoscale Metric Rules
- In the VMSS, navigate to Scaling > select Custom autoscale.
- Scale out rule:
- Metric:
Percentage CPU - Operator:
Greater than - Threshold:
75% - Duration:
10 minutes - Action:
Increase count by 2, Cool down:5 minutes.
- Scale in rule:
- Metric:
Percentage CPU - Operator:
Less than - Threshold:
25% - Action:
Decrease count by 1, Cool down:5 minutes.
Step 3: Configure App Service Deployment Slots
- Navigate to your App Service (must be on Standard (S1) tier or higher).
- Under Deployment, select Deployment slots > click + Add Slot.
- Name:
staging - Clone settings from:
Production. - Deploy new application code to the
stagingslot. - Verify functionality via
https://.-staging.azurewebsites.net - Select Swap to exchange staging with production with zero downtime.
---
06
Azure PowerShell & Azure CLI
PowerShell: Configure VMSS Rolling Upgrade Policy and Autoscale
PowerShell
# Connect and set context
Connect-AzAccount
Set-AzContext -SubscriptionId "<YOUR-SUBSCRIPTION-ID>"
$rgName = "rg-compute-core"
$vmssName = "vmss-web-prod"
# 1. Update VMSS Upgrade Policy to Rolling
$vmss = Get-AzVmss -ResourceGroupName $rgName -VMScaleSetName $vmssName
$vmss.UpgradePolicy.Mode = "Rolling"
$vmss.UpgradePolicy.RollingUpgradePolicy = New-Object Microsoft.Azure.Management.Compute.Models.RollingUpgradePolicy
$vmss.UpgradePolicy.RollingUpgradePolicy.MaxBatchInstancePercent = 20
$vmss.UpgradePolicy.RollingUpgradePolicy.MaxUnhealthyInstancePercent = 20
$vmss.UpgradePolicy.RollingUpgradePolicy.MaxUnhealthyUpgradedInstancePercent = 5
$vmss.UpgradePolicy.RollingUpgradePolicy.PauseTimeBetweenBatches = "PT0M"
Update-AzVmss -ResourceGroupName $rgName -Name $vmssName -VirtualMachineScaleSet $vmss
Write-Host "VMSS Upgrade Policy set to Rolling successfully." -ForegroundColor GreenAzure CLI: Swap App Service Deployment Slots
Bash / Shell
# Swap staging slot into production with zero downtime
az webapp deployment slot swap \
--resource-group "rg-compute-core" \
--name "app-ecommerce-core" \
--slot "staging" \
--target-slot "production"---
07
Verification Checklist
VERIFICATION CHECKLIST
0/5 (0%)
VMSS instances automatically distribute evenly across specified Availability Zones (Zone 1, 2, 3).
Simulating high CPU load triggers scale-out rule within the defined 10-minute window.
During VMSS OS upgrades, health probe ensures at least 80% capacity remains healthy and online.
App Service deployment slot swap redirects production traffic without dropping active HTTP sessions.
App settings marked as Deployment slot setting remain pinned to the slot and do not swap.
08
Common Pitfalls & Troubleshooting Matrix
| Issue | Root Cause | Resolution |
|---|---|---|
| VMSS flappping (rapid scale out and in) | Scale-in threshold is too close to scale-out threshold. | Increase margin between rules (e.g., scale out > 75%, scale in < 25%) and set cooldown to 10 mins. |
| App Service Swap fails with 500 error | Connection strings or database credentials swapped unexpectedly. | Mark environment-specific configurations as Slot Setting (sticky) so they do not move during swap. |
| Rolling upgrade halts halfway | Application health probe fails on newly upgraded batch of instances. | Check application logs on failed instances; rolling upgrade halts to protect remaining healthy instances. |
| Cannot create deployment slot | App Service Plan is running on Free (F1), Shared (D1), or Basic (B1) tiers. | Scale up the App Service Plan to Standard (S1), Premium (P1v3), or Isolated. |
---
09
Real-World Architecture / Flow
Interactive Topology & Workflow
Incoming Web Trafficgateway
Flow & Verification Handshake
Azure Load Balancer / App Gatewaygateway
Flow & Verification Handshake
VMSS Instance 01 VMSS Instance 02compute
Flow & Verification Handshake
(Zone 1default
Healthy) (Zone 2 - Healthy)
Flow & Verification Handshake
Autoscale Enginecompute
---
10
Audit & Monitoring
- Monitor VMSS autoscale actions in Activity Log:
Microsoft.Insights/autoscalesettings/scaleup/actionMicrosoft.Insights/autoscalesettings/scaledown/action- Configure Application Insights on App Service to detect HTTP 5xx spikes during deployments.
---
11
Rollback & Emergency Recovery
- Revert App Service Slot Swap:
- Simply trigger the Swap operation again between
productionandstagingto instantly restore the previous version. - Rollback VMSS Model:
- Update the VMSS image reference back to the previous image version/tag and run
Update-AzVmssInstance.
---
12
Official Documentation Reference
13
Exam Blueprint & Pro Tips (AZ-104)
Exam Blueprint & High-Yield Traps
AZ-104 High-Yield Rules:
- Upgrade Policy Modes: Remember that
Automaticupgrades all instances at once.Rollingupgrades in batches using health probes.Manualrequires admin intervention. - Slot Sticky Settings: Database connection strings, API endpoints, and slot settings marked as Deployment slot setting do not swap. General code and application files do swap.
- Minimum Tier for Slots: Staging slots require Standard (S1) tier or higher. Basic tier does NOT support slots or autoscale.
- Scale-in Rule Rule-of-Thumb: Always include both scale-out and scale-in rules. Scale-in should have an adequate cool-down time to avoid resource flapping.