This chapter covers Azure Spot Virtual Machines and their eviction policy, a cost-saving option for workloads that can tolerate interruptions. On the AZ-104 exam, Spot VMs appear in roughly 5-10% of questions related to compute resources (Objective 3.1: Implement and manage virtual machines). You'll need to understand how eviction works, the eviction policy types (Deallocate vs. Delete), pricing models, and appropriate use cases. Mastery of Spot VMs can save enterprises up to 90% on compute costs, but misconfiguration can lead to data loss or unexpected downtime.
Jump to a section
Azure Spot VMs work like airline overbooking. An airline sells more tickets than seats because they know some passengers won't show up. They offer deeply discounted 'standby' tickets to flexible travelers. When a flight is overbooked and all confirmed passengers arrive, standby passengers are bumped. Similarly, Azure has idle compute capacity that it sells at a steep discount as Spot VMs. When Azure needs the capacity back (e.g., for a priority customer or to serve higher-paying workloads), it evicts Spot VMs with a 30-second notice. Just as standby passengers are compensated with a voucher, Spot VMs get a 30-second warning before termination. The airline doesn't care which standby passenger gets bumped—they just need the seat. Azure doesn't care which Spot VM is evicted—it just needs the compute. The discount (up to 90%) is the incentive for taking the risk. Standby passengers can rebook; Spot VMs can be redeployed if capacity becomes available. The key difference: airlines overbook intentionally; Azure reclaims capacity dynamically based on demand. Both systems rely on statistical modeling of usage patterns to maximize resource utilization while offering savings to flexible users.
What Are Azure Spot VMs?
Azure Spot VMs are unused compute capacity that Microsoft offers at a significant discount—up to 90% compared to pay-as-you-go pricing. They are ideal for workloads that are fault-tolerant, stateless, or can handle interruptions, such as batch processing jobs, dev/test environments, large-scale data analytics, or rendering workloads. Spot VMs are not suitable for production workloads that require high availability, real-time responses, or persistent state.
How Eviction Works
Azure reclaims Spot VMs when it needs the capacity back for higher-priority workloads. The eviction process is not immediate; Azure provides a 30-second warning before the VM is stopped or deleted. During this 30-second window, you can capture state, save logs, or gracefully shut down applications. After 30 seconds, the VM is either deallocated (stopped but not deleted, preserving disks and IPs) or deleted (permanently removed with all associated resources).
Eviction Policy: Deallocate vs. Delete
When creating a Spot VM, you must choose an eviction policy: - Deallocate: The VM is stopped, and its resources (disks, network interfaces) remain allocated. You can start the VM again later if capacity becomes available. This is useful for batch jobs that can resume from a checkpoint. - Delete: The VM and its associated disks are permanently deleted. This is suitable for stateless workloads where you can simply recreate the VM.
Eviction Types and Reasons
Azure determines evictions based on capacity needs. There are two types of evictions: - Capacity Eviction: Azure needs the physical resources for higher-priority workloads. This is the most common type. - Price Eviction: The Spot price exceeds the maximum price you set (if you set a max price). Spot pricing fluctuates; if the current Spot price goes above your max price, your VM is evicted.
Spot Pricing Model
Spot VM pricing is dynamic and varies by region, VM size, and time. The price is set by Azure based on supply and demand. You can set a maximum price per hour; if the Spot price exceeds your max, the VM is evicted (price eviction). If you do not set a max price, you pay the current Spot price, and eviction is based solely on capacity needs. The discount can range from 10% to 90%.
How to Create a Spot VM
You can create a Spot VM using the Azure portal, CLI, PowerShell, or ARM templates. In the portal, during VM creation, under 'Compute' > 'Disk' > 'Advanced', select 'Spot' and choose the eviction policy. With CLI:
az vm create \
--resource-group myGroup \
--name mySpotVM \
--image UbuntuLTS \
--size Standard_D2s_v3 \
--priority Spot \
--eviction-policy Deallocate \
--max-price 0.05The --priority Spot flag makes it a Spot VM. --max-price is optional; omitting it means you accept any price.
Spot VM Limitations
Not all VM sizes support Spot VMs. Typically, you can use any size that is generally available.
Spot VMs cannot be migrated to other regions or reserved with Reserved Instances.
They are not covered by the Azure SLA (99.9% uptime).
You cannot use Azure Hybrid Benefit for Spot VMs.
Spot VMs cannot be part of an availability set or availability zone (though they can be deployed in a zone).
Best Practices for Spot VMs
Use multiple Spot VMs across different regions and zones to reduce the impact of eviction.
Design applications to be stateless and resilient to interruptions (e.g., using Azure Batch, AKS cluster with Spot node pools).
Use Azure Monitor and alerts to track evictions and redeploy VMs automatically.
Set a maximum price that is realistic; setting it too low may cause frequent price evictions.
For long-running jobs, implement checkpoint/restart logic.
Monitoring Evictions
You can monitor evictions via Azure Monitor metrics (e.g., 'VM Eviction Count') or by using the Azure Instance Metadata Service (IMDS). The scheduled events endpoint provides a 30-second warning:
curl -H "Metadata:true" "http://169.254.169.254/metadata/scheduledevents?api-version=2019-08-01"This returns events like 'Preempt' for Spot VMs. You can then gracefully handle eviction.
Interaction with Other Azure Services
Azure Batch: Batch pools can use Spot VMs as compute nodes. Batch automatically handles eviction by retrying tasks.
Azure Kubernetes Service (AKS): AKS supports Spot node pools. Nodes are evicted, and pods are rescheduled.
Azure Virtual Machine Scale Sets: Scale sets can have Spot VM instances. You can use the 'scale-in' policy to prioritize eviction of Spot VMs.
Azure Logic Apps: Can trigger redeployment on eviction events.
Cost Comparison
| Pricing Model | Typical Discount | SLA | Eviction Risk | |---------------|------------------|-----|---------------| | Pay-as-you-go | None | 99.9% | None | | Reserved Instance | 30-70% | 99.9% | None | | Spot VM | 10-90% | None | High |
Common Exam Scenarios
You need to run a batch job that can take up to 6 hours. You want to minimize cost. Answer: Use Spot VMs with Deallocate policy and checkpointing.
A production web app needs 99.99% uptime. Should you use Spot VMs? No, because they have no SLA.
You set a max price of $0.02 for a Standard_D2s_v3 Spot VM. Current Spot price is $0.01. What happens if price rises to $0.03? The VM is evicted due to price eviction.
You create a Spot VM with Delete policy. It gets evicted. What happens to the OS disk? It is deleted.
Create a Spot VM
Using the Azure portal, CLI, or ARM template, you create a VM with priority set to Spot. You must choose an eviction policy: Deallocate or Delete. Optionally, you set a maximum price per hour. The VM is deployed like a regular VM but with a different billing model. The VM size must support Spot VMs. Once created, the VM runs normally and you pay the current Spot price.
Azure detects capacity need
At any time, Azure's capacity management system determines that the physical resources hosting your Spot VM are needed for higher-priority workloads (e.g., a pay-as-you-go VM or a Reserved Instance). This triggers an eviction event. Alternatively, if you set a max price and the Spot price exceeds it, a price eviction is triggered.
30-second warning sent
Azure sends a scheduled event to the VM via the Azure Instance Metadata Service (IMDS). The VM receives a 30-second notice before eviction. You can configure your application to listen for this event and perform graceful shutdown tasks, such as saving state, closing connections, or uploading logs. The event type is 'Preempt'.
Eviction executed
After 30 seconds, Azure executes the eviction based on the policy. If Deallocate, the VM is stopped (powered off) but its disks, network interfaces, and public IP remain allocated. You can start the VM later if capacity becomes available. If Delete, the VM and its associated managed disks are permanently deleted. The VM's resources are released back to the Azure free pool.
Post-eviction actions
After eviction, you can redeploy the VM if capacity is available. For Deallocate policy, you can start the VM again. For Delete policy, you must recreate the VM. You can automate this using Azure Logic Apps, Functions, or scale sets. Monitor evictions using Azure Monitor metrics or logs. The VM's billing stops immediately after eviction.
Scenario 1: Large-Scale Batch Processing
A pharmaceutical company runs gene sequencing jobs that take 8 hours each. The workload is embarrassingly parallel and can tolerate interruptions. They deploy 1000 Spot VMs in a single region using a Virtual Machine Scale Set with Deallocate policy. Each VM writes intermediate results to Azure Blob Storage every 5 minutes. If a VM is evicted, the job resumes from the last checkpoint using the stored data. The company saves 80% on compute costs compared to pay-as-you-go. The main challenge is managing eviction rates; during peak hours, up to 20% of VMs may be evicted, requiring robust checkpointing and retry logic.
Scenario 2: Dev/Test Environments
A startup uses Spot VMs for their CI/CD pipeline and development environments. They have a mix of Spot VMs for build agents and test runners. Since developers can tolerate occasional delays, they use Delete policy to ensure no stale resources remain. They set a max price of $0.10 per hour to avoid price spikes. They noticed that during Black Friday sales, Spot prices increased by 300%, causing frequent evictions. They mitigated by using multiple VM sizes and regions, and by implementing a fallback to pay-as-you-go VMs for critical builds.
Scenario 3: Rendering Farm
A media company renders 3D animations using a render farm of Spot VMs. Jobs are broken into frames, each frame rendered independently. They use AKS with Spot node pools to manage the rendering workload. When a node is evicted, the scheduler moves the pod to another node. They configure the eviction policy to Delete because each pod is stateless and can be recreated. The company saves 70% on compute costs. Misconfiguration: initially they used Deallocate policy, which left many stopped VMs with attached disks, incurring storage costs. Switching to Delete reduced costs further.
What AZ-104 Tests on Spot VMs
The exam focuses on Objective 3.1: Implement and manage virtual machines. Key subtopics: Spot VM pricing, eviction policies (Deallocate vs. Delete), use cases, and limitations. You must know that Spot VMs have no SLA, cannot be migrated, and are not eligible for Azure Hybrid Benefit. The exam often presents scenarios where you need to choose the most cost-effective solution for a fault-tolerant workload.
Common Wrong Answers
Choosing Reserved Instances for fault-tolerant workloads: Candidates often pick Reserved Instances because they offer discounts, but they require a 1- or 3-year commitment and are not as flexible as Spot VMs for interruptible workloads.
Selecting Deallocate policy for stateless workloads: Deallocate keeps disks attached, incurring storage costs. For stateless workloads, Delete is more cost-effective.
Thinking Spot VMs have an SLA: The exam will have a distractor saying 'Spot VMs provide 99.9% uptime' – this is false.
Setting max price too low: Candidates may set max price very low to save money, but this causes frequent price evictions. The correct approach is to set a realistic max price or omit it.
Specific Numbers and Terms
Eviction warning time: 30 seconds.
Discount range: 10-90%.
Eviction types: Capacity eviction and Price eviction.
Eviction policies: Deallocate and Delete.
Max price: optional; if set, VM evicted when Spot price exceeds it.
Spot VMs cannot be used with: Reserved Instances, Azure Hybrid Benefit, Availability Sets, SLA.
Edge Cases
Can you convert a Spot VM to pay-as-you-go? No, you must create a new VM.
Can you use Spot VMs in an availability zone? Yes, but they are not protected by the zone's SLA.
What happens if you don't set a max price? You pay the current Spot price, and only capacity evictions occur.
How to Eliminate Wrong Answers
If the question mentions 'no SLA', 'interruptible', or 'fault-tolerant', lean towards Spot VMs.
If the question says 'production' or 'critical', eliminate Spot VMs.
If the question asks about cost savings for a batch job that can be interrupted, Spot VMs are the best choice.
If the question mentions 'persistent data' or 'stateful', avoid Delete policy.
Spot VMs offer up to 90% discount but have no SLA.
Eviction warning time is exactly 30 seconds.
Two eviction policies: Deallocate (stop) and Delete (remove).
Eviction can be due to capacity need or price exceedance.
Spot VMs cannot be used with Reserved Instances or Azure Hybrid Benefit.
Design workloads to be stateless and checkpoint progress.
Monitor evictions using Azure Monitor or IMDS scheduled events.
These come up on the exam all the time. Here's how to tell them apart.
Spot VM with Deallocate Policy
VM is stopped, not deleted.
OS disk and data disks remain attached.
Public IP and NIC preserved.
Can be started later if capacity available.
Storage costs continue for disks.
Spot VM with Delete Policy
VM and its disks are permanently deleted.
All resources are released.
No storage costs after eviction.
Must recreate VM from scratch.
Best for stateless workloads.
Mistake
Spot VMs provide a 99.9% uptime SLA.
Correct
Spot VMs have no SLA. They can be evicted at any time with a 30-second warning.
Mistake
You can convert a Spot VM to a pay-as-you-go VM.
Correct
No conversion is possible. You must create a new VM with the desired priority.
Mistake
Setting a max price guarantees you never pay more than that.
Correct
Setting a max price can cause price eviction if the Spot price exceeds it, but you will never be charged more than your max price while the VM runs.
Mistake
Spot VMs can be used with Reserved Instances to save more.
Correct
Reserved Instances cannot be applied to Spot VMs. They are mutually exclusive.
Mistake
Eviction always means the VM is deleted.
Correct
Eviction behavior depends on the policy: Deallocate stops the VM, Delete removes it entirely.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
The warning time is 30 seconds. Azure sends a scheduled event via IMDS. Your application can listen for this to gracefully shut down. After 30 seconds, the VM is deallocated or deleted based on the eviction policy.
No, Azure Hybrid Benefit (AHB) cannot be applied to Spot VMs. AHB is only available for pay-as-you-go and Reserved Instances. If you need to use your own Windows Server license, you must use a regular VM.
You can use Azure Logic Apps, Azure Functions, or Azure Automation to detect eviction events and redeploy VMs. For scale sets, set the 'scale-in' policy to prioritize Spot instances. You can also use Azure Batch or AKS which handle eviction automatically.
If you don't set a max price, you pay the current Spot price, and eviction is based solely on capacity needs (not price). This is recommended to avoid price evictions, but you may pay more during high-demand periods.
No, Spot VMs cannot be added to an availability set. However, they can be deployed in an availability zone (though without SLA). For high availability, use multiple Spot VMs across zones.
No, because they can be evicted at any time. Production databases require persistence and high availability. Use pay-as-you-go or Reserved Instances for production databases.
Capacity eviction occurs when Azure needs the physical resources for higher-priority workloads. Price eviction occurs when the Spot price exceeds your set maximum price. If you don't set a max price, only capacity eviction applies.
You've just covered Azure Spot VMs and Eviction Policy — now see how well it sticks with free AZ-104 practice questions. Full explanations included, no account needed.
Done with this chapter?