0Pricing
Cloud & IT Cert Prep · Lesson

Right-Sizing and Autoscaling

Analyse VM performance data to right-size instances, implement scheduled autoscale for predictable workloads, and use VMSS spot instances for batch workloads.

Right-Sizing and Autoscaling 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 Is Right-Sizing?

Right-sizing is the process of matching Azure VM or service SKUs to the actual resource requirements of your workload — neither over-provisioning (wasting money) nor under-provisioning (risking performance degradation). Most organisations initially over-provision by 30–50% out of caution when migrating from on-premises. Regular right-sizing analysis, typically monthly, can recover a significant portion of that over-spend without impacting application performance.

Analysing VM Performance Data

Use Azure Monitor metrics and VM Insights to collect CPU, memory, disk IOPS, and network throughput data over at least 30 days. Look for the peak (P95 or P99) utilisation, not the average, to ensure the right-sized VM can handle traffic spikes. Azure Advisor's right-sizing recommendation uses a 7-day lookback by default, but you can extend this to 30 or 60 days in the Advisor configuration for more representative data.

# Get P95 CPU utilisation for a VM over 30 days
az monitor metrics list \
  --resource /subscriptions/<sub>/resourceGroups/myRG/providers/Microsoft.Compute/virtualMachines/myVM \
  --metric 'Percentage CPU' \
  --aggregation Percentile \
  --interval P1D \
  --start-time 2024-05-01T00:00:00Z \
  --end-time 2024-06-01T00:00:00Z

VM SKU Families and Resizing

Azure VMs are organised into SKU families optimised for different workloads: D-series (general purpose), E-series (memory optimised), F-series (compute optimised), N-series (GPU), and L-series (storage optimised). If a VM's CPU usage is low but memory is high, moving from a D-series to an E-series at the same vCPU count gives more RAM at similar cost. Resizing a VM in Azure typically requires a brief restart of a few minutes.

# Resize a VM to a smaller SKU
az vm resize \
  --resource-group myRG \
  --name myVM \
  --size Standard_D2s_v5

Scheduled Autoscaling for Predictable Workloads

Scheduled autoscaling is the right choice when workload patterns are predictable. A retail application that sees high traffic during business hours and near-zero traffic overnight can be configured with a scale-out schedule at 07:00 and a scale-in schedule at 22:00. Virtual Machine Scale Sets (VMSS) and App Service both support scheduled autoscale rules. This approach is simpler and more cost-predictable than metric-based autoscaling for known load patterns.

# Add a scheduled autoscale rule to a VMSS (scale out at 07:00, in at 22:00 UTC)
az monitor autoscale create \
  --resource-group myRG \
  --resource myVMSS \
  --resource-type Microsoft.Compute/virtualMachineScaleSets \
  --name myAutoscale \
  --min-count 2 --max-count 10 --count 2

Metric-Based Autoscaling

Metric-based autoscaling adds or removes instances dynamically in response to real-time metrics such as CPU percentage, HTTP request queue length, or custom metrics published via Azure Monitor. You define scale-out rules (when to add instances) and scale-in rules (when to remove instances) with cooldown periods to prevent rapid flapping. Best practice is to set a scale-out threshold lower than the scale-in threshold — for example, scale out at >70% CPU and scale in at <30% CPU — with a 5-minute cooldown.

# Add a metric-based scale-out rule (CPU > 70% for 5 minutes)
az monitor autoscale rule create \
  --autoscale-name myAutoscale \
  --resource-group myRG \
  --scale out 1 \
  --condition 'Percentage CPU > 70 avg 5m'

VMSS Spot Instances for Batch Workloads

Azure Spot VMs allow you to use unused Azure capacity at discounts of up to 90% compared to pay-as-you-go prices. The trade-off is that Azure can evict spot VMs with a 30-second notice when it needs the capacity back. This makes spot instances ideal for interruptible batch workloads like rendering, scientific computing, and data processing pipelines. VMSS supports mixing regular VMs (for a baseline) with spot VMs (for burst capacity) in the same scale set using a priority mix policy.

# Create a VMSS with spot instances for batch workloads
az vmss create \
  --resource-group myRG \
  --name myBatchVMSS \
  --image UbuntuLTS \
  --priority Spot \
  --eviction-policy Deallocate \
  --max-price -1 \
  --instance-count 5

App Service Autoscaling

Azure App Service autoscaling works at the App Service Plan level — adding or removing worker instances based on rules you configure. Metric triggers available include HTTP queue length, CPU percentage, and memory percentage. The Standard tier and above support manual and autoscale; the Basic tier only supports manual scaling. For serverless workloads, consider using Azure Functions on the Consumption Plan, which scales to zero and charges only per execution, eliminating idle instance cost entirely.

# Enable autoscale on an App Service plan
az monitor autoscale create \
  --resource-group myRG \
  --resource myAppServicePlan \
  --resource-type Microsoft.Web/serverfarms \
  --name webAppAutoscale \
  --min-count 1 --max-count 5 --count 1

Autoscaling Pitfalls to Avoid

Common autoscaling pitfalls: session affinity — if your app stores session state in VM memory, scaling in will lose sessions; use Redis Cache or database-backed sessions instead. Slow start-up times — if VMs or containers take 10 minutes to warm up, metric-based autoscaling cannot respond fast enough; pre-warm with scheduled scale-out before predicted peaks. Scale-in too aggressive — terminating instances while in-flight requests are processing causes errors; configure connection draining and a generous cooldown period.

Database and PaaS Right-Sizing

Right-sizing applies to PaaS services too. Azure SQL Database on the DTU model can be downsized if the DTU percentage is consistently below 50%. The vCore model allows independent CPU and storage scaling. Azure Cache for Redis can be downsized from Premium to Standard tier if persistence and geo-replication are not needed. Azure Kubernetes Service node pools can use the Cluster Autoscaler to scale nodes in and out based on pod pending and idle states.

# Change Azure SQL Database service objective (tier)
az sql db update \
  --resource-group myRG \
  --server mySQLServer \
  --name myDatabase \
  --service-objective S2

Continuous Right-Sizing Practice

Right-sizing is not a one-time activity. Workloads change over time — traffic patterns shift, features are added, and user bases grow or shrink. Build a monthly right-sizing review into your FinOps process: pull Advisor recommendations, review the top 10 under-utilised VMs and over-provisioned PaaS services, and create work items for the owning teams. Track savings realised vs. recommendations generated to demonstrate FinOps ROI to leadership.

Combining Right-Sizing with Reservations

The optimal cost strategy is to right-size first, then reserve. Purchasing a Reserved VM Instance for an over-provisioned VM locks in a commitment to the wrong SKU. Right-size the VM to its correct size first, observe the new utilisation for 30 days to confirm stability, then purchase a reservation for that right-sized SKU. This two-step approach maximises the discount while avoiding wasted reserved capacity.

Quick Check

Test your understanding of Microsoft Azure Fundamentals (AZ-900) concepts from this lesson.

Lesson Recap

In this lesson you learned: right-sizing matches VM SKUs to actual workload requirements using performance metrics, scheduled and metric-based autoscaling dynamically adjust capacity to match demand, and Spot VMs offer up to 90% discounts for interruptible batch workloads. Next up we explore Azure Savings Plans and Reservations for committed workloads.

Frequently asked questions

Is the “Right-Sizing and Autoscaling” lesson free?

Yes — the full text of “Right-Sizing and Autoscaling” 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 “Right-Sizing and Autoscaling”?

Analyse VM performance data to right-size instances, implement scheduled autoscale for predictable workloads, and use VMSS spot instances for batch workloads. 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 “Right-Sizing and Autoscaling” 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.

All lessons in this course

  1. Identifying and Eliminating Waste
  2. Right-Sizing and Autoscaling
  3. Azure Savings Plans and Reservations
  4. FinOps and Chargeback Models
← Back to Cloud & IT Cert Prep