This chapter covers Azure Spot Virtual Machines, a cost-saving option that leverages unused Azure compute capacity. Understanding Spot VMs is essential for the AZ-900 exam, as it tests your knowledge of Azure's pricing models and when to use them. This objective falls under 'Describe Azure architecture and services' (20-25% of the exam). By the end of this chapter, you will understand what Spot VMs are, how they work, their eviction policies, and how to design workloads that can tolerate interruptions. You'll also learn common exam traps and misconceptions.
Jump to a section
Imagine you run a small business that occasionally needs to ship urgent packages across the country. You could buy a dedicated cargo plane for millions of dollars (like a reserved virtual machine), but that's wasteful when you only need it a few days a month. Instead, you use a 'last-minute seat' service offered by airlines. The airline sells empty cargo space on flights that are about to depart, at a steep discount—sometimes 80% off. However, there's a catch: if a higher-paying customer needs that space, the airline can bump your package off the plane with no notice. You only pay for the space if your package actually flies, and you accept the risk that it might not arrive on time. This is exactly how Azure Spot Virtual Machines work. Azure has unused compute capacity in its data centers. It offers this capacity at a deep discount (typically 60-90% off pay-as-you-go prices) via Spot VMs. But Azure can evict (reclaim) your Spot VM at any time if it needs the capacity for higher-priority workloads (like standard VMs or reserved instances). You pay only for the minutes the VM runs, and you must design your application to handle eviction gracefully. Just as the airline maximizes profit by selling empty seats, Azure maximizes utilization of its infrastructure by offering spare capacity at low cost. You get huge savings, but only if your workload is fault-tolerant and interruptible.
What Are Azure Spot Virtual Machines?
Azure Spot Virtual Machines (formerly Azure Low-Priority VMs for Batch and Azure Spot VMs for other workloads) allow you to run virtual machines at a significant discount—typically 60-90% off the standard pay-as-you-go price. The catch: Azure can evict (deallocate or delete) these VMs at any time when it needs the capacity for higher-priority workloads. Spot VMs are ideal for workloads that are fault-tolerant, interruptible, and can handle sudden termination, such as batch processing jobs, dev/test environments, large-scale data analysis, and containerized workloads using Azure Kubernetes Service (AKS).
How Spot VMs Work: The Mechanism
Azure has a vast global infrastructure with millions of servers. Not all capacity is used at all times. To avoid wasting idle capacity, Azure offers it as Spot VMs at a deep discount. When you create a Spot VM, you specify the maximum price you are willing to pay per hour. If the current spot price is below your maximum, Azure allocates your VM. The spot price fluctuates based on supply and demand. If demand increases (e.g., during peak hours), Azure may raise the spot price. If your maximum price is exceeded, Azure will evict your VM. Alternatively, Azure can evict your VM simply because it needs the capacity for standard VMs or reserved instances, even if the spot price hasn't changed.
Eviction Policies
Azure offers two eviction policies:
Deallocate (Stop-Deallocate): The VM is stopped and deallocated. You stop paying for compute costs but continue to pay for the attached managed disk and any static IP addresses. You can restart the VM later if capacity becomes available.
Delete: The VM and its underlying resources are deleted. This is suitable for stateless workloads where the VM can be recreated from a template.
You can set the eviction policy when creating the VM. The default is Deallocate.
Maximum Price and Billing
When you create a Spot VM, you set a maximum price per hour (in the currency of your subscription). This can be:
-1 (or blank): You don't want to cap the price; you'll pay the current spot price regardless of how high it goes, but you'll still be evicted if capacity is needed. This is often the best option because you always get the discount, and eviction is based on capacity, not price.
A specific value: You set a maximum, e.g., $0.10 per hour. Azure will only run the VM if the current spot price is at or below $0.10. If the spot price rises above $0.10, your VM will be evicted.
Billing is per minute, and you only pay for the time the VM runs. If a VM is evicted within the first minute, you are not charged.
Capacity and Availability
Spot VMs are not guaranteed. Azure does not offer an SLA for Spot VMs. They are best-effort capacity. When you request a Spot VM, Azure may not be able to fulfill it if there is insufficient capacity. You can request Spot VMs in specific Azure regions and availability zones, but some regions may have higher eviction rates than others. You can use the Azure Spot Eviction Rate data (available in the portal or via CLI) to see historical eviction rates per region and VM size.
Use Cases and Limitations
Good for: - Batch processing jobs (e.g., rendering, financial modeling, genomics) - Dev/test environments that can tolerate interruptions - Large-scale data analytics (e.g., using Azure Data Lake, HDInsight, or Databricks) - Containerized workloads with AKS (Spot node pools) - Stateless web servers behind a load balancer
Not good for: - Production workloads that require high availability and an SLA - Stateful applications (unless state is stored externally, e.g., in Azure SQL or Cosmos DB) - Workloads that cannot be interrupted or have strict deadlines
Comparing to On-Premises
On-premises, you buy physical servers that are always available regardless of usage. You pay full capital and operational costs even when servers are idle. Azure Spot VMs are the opposite: you only pay for what you use, but you risk losing capacity at any time. It's like renting a space in a shared office versus owning your own building: you save money but have less control.
Azure Portal and CLI Touchpoints
Azure Portal: 1. Go to 'Virtual machines' and click 'Create'. 2. In the 'Basics' tab, under 'Instance details', select 'Azure Spot instance'. 3. Set the eviction policy (Deallocate or Delete) and maximum price. 4. Complete the rest of the VM configuration.
Azure CLI:
az vm create --resource-group myRG --name mySpotVM --image Ubuntu2204 --admin-username azureuser --generate-ssh-keys --priority Spot --eviction-policy Deallocate --max-price -1Azure PowerShell:
New-AzVm -ResourceGroupName 'myRG' -Name 'mySpotVM' -Location 'EastUS' -VirtualNetworkName 'myVnet' -SubnetName 'mySubnet' -SecurityGroupName 'myNSG' -PublicIpAddressName 'myPublicIP' -OpenPorts 80,22 -Priority 'Spot' -EvictionPolicy 'Deallocate' -MaxPrice -1Best Practices
Design applications to be stateless or store state externally (e.g., in Azure Storage, Cosmos DB, or SQL Database).
Use Azure Functions or Logic Apps to handle eviction notifications (via Azure Metadata Service or Event Grid).
Combine Spot VMs with standard VMs in a scale set to ensure baseline capacity.
Monitor eviction rates and adjust region/VM size selection.
Use Azure Spot VMs with Azure Batch or AKS for automatic recovery.
Identify Suitable Workloads
Before creating Spot VMs, evaluate your workloads. Spot VMs are best for batch processing, dev/test, and stateless applications that can tolerate interruptions. For example, a data processing job that runs nightly can be split into small tasks; if a Spot VM is evicted, another VM can pick up the task. Avoid using Spot VMs for critical production systems or stateful applications unless you have external state management. On the exam, remember that Spot VMs are ideal for fault-tolerant, interruptible workloads.
Create a Spot VM via Portal
In the Azure portal, navigate to 'Virtual machines' and click 'Create'. In the 'Basics' tab, under 'Instance details', check 'Azure Spot instance'. Select the eviction policy: 'Deallocate' (default) or 'Delete'. Set the maximum price; using -1 means no cap. Choose a region and size. Note that some VM sizes may have higher eviction rates. Complete the configuration and click 'Review + create'. Azure will attempt to allocate the VM; if capacity is insufficient, you'll get an error.
Configure Eviction Policy
The eviction policy determines what happens when Azure needs to reclaim capacity. 'Deallocate' stops the VM and releases its hardware allocation; you keep the disks and IP addresses but stop paying compute costs. 'Delete' removes the VM and its associated resources (disks, NIC, etc.). Choose 'Deallocate' if you want to preserve the VM configuration for later use; choose 'Delete' for stateless workloads where you can recreate the VM from a template. On the exam, know that the default is 'Deallocate'.
Set Maximum Price
The maximum price is the highest hourly rate you're willing to pay. You can set a specific value (e.g., $0.05) or -1 to accept any price. If the current spot price exceeds your max, the VM will be evicted. Using -1 is recommended because eviction is more often due to capacity needs than price spikes. However, if you have a strict budget, you can set a cap. Note that you are billed at the current spot price, not your maximum, as long as the spot price is below your max.
Handle Eviction Notifications
Azure provides a 30-second warning before eviction via the Azure Metadata Service (Scheduled Events). Your application can listen for this event and gracefully shut down. For example, a batch job can checkpoint progress. Alternatively, you can use Azure Event Grid to trigger a function to save state. On the exam, remember that you can detect eviction via Scheduled Events or Azure Monitor. Without handling eviction, data loss may occur.
Scenario 1: Large-Scale Batch Rendering for a Film Studio
A film studio needs to render high-definition frames for an animated movie. The rendering workload is compute-intensive and can be split into thousands of independent tasks. The studio uses Azure Batch with a pool of Spot VMs (e.g., NCas_v4 series with NVIDIA GPUs). They set the eviction policy to 'Delete' because each task is stateless and can be retried. The spot price offers 80% savings compared to pay-as-you-go. During peak rendering, the team monitors eviction rates and adjusts the pool to include a few standard VMs for baseline capacity. If a Spot VM is evicted, Azure Batch automatically resubmits the task to another VM. The studio saves millions of dollars. What goes wrong if they don't handle eviction? Without checkpointing, partially completed frames would be lost, requiring re-rendering. The team uses Azure Blob Storage to store intermediate results, ensuring fault tolerance.
Scenario 2: Dev/Test Environment for a SaaS Startup
A startup building a SaaS application uses Spot VMs for their dev and test environments. They have multiple branches, each deployed to a separate Spot VM. Developers run automated tests that can be interrupted and restarted. The startup sets the eviction policy to 'Deallocate' so that the VM configuration (disks) persists. When a developer pushes code, a CI/CD pipeline creates a Spot VM, runs tests, and then deletes it. The startup saves 70% on compute costs. However, if they accidentally use Spot VMs for the production environment, users experience downtime when eviction occurs. The startup learns to use standard VMs with an availability set for production.
Scenario 3: Big Data Analytics with Azure Databricks
A financial services company runs large-scale risk analysis using Azure Databricks. They create a Spark cluster using Spot VMs for worker nodes and standard VMs for the driver node. The workers are stateless; if a worker is evicted, Spark recomputes the lost partitions from other nodes. The company uses the 'Delete' eviction policy for workers. They monitor eviction rates using Azure Monitor and choose regions with lower eviction rates. Cost savings exceed 60%. The challenge: if the driver node is also a Spot VM and gets evicted, the entire cluster fails. They avoid this by using a standard VM for the driver. The exam might test that Spot VMs are not recommended for critical components like database servers or controllers.
Exam Objective: 2.2 – Describe Azure Virtual Machines (including Spot VMs)
The AZ-900 exam tests your ability to identify when to use Spot VMs and how they differ from standard VMs. You are not expected to know CLI commands or PowerShell, but you should understand the concepts: eviction policies, pricing, and use cases.
Common Wrong Answers and Why Candidates Choose Them
"Spot VMs are always available at a fixed discount." – Wrong. Spot VMs have no SLA and can be evicted. Candidates assume a discount means guaranteed availability, but Azure can reclaim capacity at any time.
"Spot VMs are cheaper than Reserved Instances." – Partially true, but Reserved Instances offer a discount for a commitment (1 or 3 years) and are more reliable. Spot VMs are cheaper on a per-hour basis but come with eviction risk. The exam may ask which is best for a steady-state workload; the answer is Reserved Instances, not Spot.
"You can use Spot VMs for any workload." – Wrong. Spot VMs are only for fault-tolerant, interruptible workloads. Production databases or web servers should not use Spot VMs.
"Eviction only happens when the spot price exceeds your maximum." – Wrong. Eviction can also happen when Azure needs capacity for higher-priority workloads, even if the spot price is below your max.
Specific Terms and Values
Eviction policy: Deallocate (default) or Delete.
Maximum price: -1 (no cap) or a specific value.
Spot VM discount: 60-90% off pay-as-you-go.
No SLA: Spot VMs do not have an SLA.
Scheduled Events: 30-second warning before eviction.
Azure Batch and AKS: Common services that use Spot VMs.
Edge Cases and Tricky Distinctions
Spot VMs vs. Reserved Instances: Reserved Instances are for predictable, steady-state workloads; Spot VMs are for flexible, interruptible workloads. The exam may present a scenario where a company needs to run a batch job that can be interrupted. The correct answer is Spot VMs.
Spot VMs vs. Low-Priority VMs (Azure Batch): Low-Priority VMs are the same as Spot VMs but used in Azure Batch. The exam may use either term.
Eviction Policy – Deallocate vs. Delete: Deallocate preserves disks and IPs; Delete removes everything. The exam may ask which policy to use for a stateless workload. Answer: Delete.
Memory Trick: "SPOT" = Savings, Preemptible, Only for Temporary workloads.
Decision Tree for Eliminating Wrong Answers:
Is the workload interruptible? If yes, consider Spot. If no, eliminate Spot.
Does the workload need an SLA? If yes, eliminate Spot.
Is the workload stateful? If yes, eliminate Spot unless state is stored externally.
Is the priority cost savings over reliability? If yes, Spot may be correct.
Azure Spot VMs offer significant cost savings (60-90%) by using unused Azure capacity.
Spot VMs have no SLA and can be evicted at any time; they are not for production workloads.
Two eviction policies: Deallocate (default) and Delete.
Maximum price can be set to -1 (no cap) or a specific value; eviction can occur due to capacity needs, not just price.
Use Scheduled Events to get a 30-second warning before eviction.
Common use cases: batch processing, dev/test, big data analytics, and AKS node pools.
Spot VMs are not suitable for stateful applications unless state is stored externally.
These come up on the exam all the time. Here's how to tell them apart.
Azure Spot Virtual Machines
Discount: 60-90% off pay-as-you-go
No commitment required
No SLA; can be evicted at any time
Best for fault-tolerant, interruptible workloads
Billed per minute at spot price
Azure Reserved Virtual Machine Instances
Discount: up to 72% off pay-as-you-go
1 or 3-year commitment required
SLA included (99.9% for multi-instance)
Best for predictable, steady-state workloads
Billed at fixed discounted rate
Mistake
Spot VMs are always cheaper than pay-as-you-go VMs.
Correct
True, but not guaranteed. The discount is typically 60-90%, but the spot price can fluctuate. However, the discount is applied to the current pay-as-you-go rate. You always pay less than pay-as-you-go, but the exact discount varies.
Mistake
Spot VMs are only available in certain regions.
Correct
Spot VMs are available in most Azure regions, but capacity and eviction rates vary. You can use Azure Spot Eviction Rate data to choose a region with lower eviction rates.
Mistake
You cannot use Spot VMs with Azure Kubernetes Service (AKS).
Correct
You can! AKS supports Spot node pools. This is a common use case for running containerized workloads at low cost. The exam may test this.
Mistake
If a Spot VM is evicted, you lose all data on the OS disk.
Correct
If the eviction policy is 'Deallocate', the managed disks are preserved, so data on the OS disk remains. If the policy is 'Delete', the disks are deleted. Always use external storage for critical data.
Mistake
Spot VMs are the same as Reserved Instances.
Correct
No. Reserved Instances require a 1 or 3-year commitment and provide a discount in exchange for reliability. Spot VMs have no commitment but no reliability. They are for different use cases.
Standard VMs are dedicated capacity with an SLA (99.9% for multi-instance) and predictable pricing. Spot VMs use spare capacity at a discount but can be evicted without notice. Standard VMs are for reliable workloads; Spot VMs are for cost-sensitive, interruptible workloads.
Generally no, because Spot VMs have no SLA and can be evicted. However, if your application is designed to handle interruptions (e.g., stateless microservices behind a load balancer), you could use them for production, but it's risky. The exam advises against it.
Use Deallocate if you want to preserve the VM's disks and configuration so you can restart later. Use Delete for stateless workloads where you can recreate the VM from a template. Default is Deallocate.
Azure provides a 30-second warning via Scheduled Events. Your application can listen for this event to gracefully shut down. This is important for exam questions about handling eviction.
Most VM sizes support Spot VMs, but some sizes (especially GPU and high-memory) may have limited capacity. You can check availability in the Azure portal or via CLI.
Yes. You can create a scale set with Spot VMs. This is common for autoscaling batch workloads. Scale sets can automatically replace evicted VMs.
Your VM will be evicted. However, if you set max price to -1, eviction is based on capacity needs, not price. The exam may test that -1 is the recommended option.
You've just covered Azure Spot Virtual Machines — now see how well it sticks with free AZ-900 practice questions. Full explanations included, no account needed.
Done with this chapter?