How Spot VMs Work
Azure's data centres are never 100% utilised. At any given time, some physical servers have spare capacity. Azure sells this spare capacity at a steep discount as Spot instances. When Azure needs that capacity back for regular customers, your Spot VM gets evicted.
Typical Spot Savings
| VM Size | Pay-As-You-Go | Typical Spot Price | Savings |
|---|---|---|---|
| Standard_D4s_v5 | ~₹13,000/month | ~₹1,300–3,900/month | 70–90% |
| Standard_E8s_v5 | ~₹26,000/month | ~₹2,600–7,800/month | 70–90% |
| Standard_F8s_v2 | ~₹16,000/month | ~₹1,600–4,800/month | 70–90% |
Eviction Policies
There are two eviction policies that determine when your Spot VM can be evicted:
Capacity Only (Default)
Your VM is only evicted when Azure needs the capacity back. The Spot price you pay is whatever the current market rate is — it fluctuates, but you pay whatever it is at the time.
Price or Capacity
Your VM is evicted if either: (1) Azure needs the capacity, OR (2) the current Spot price exceeds your maximum price. You set a maximum price you're willing to pay per hour — if Spot prices rise above that, your VM is evicted.
Eviction Types
When a Spot VM is evicted, what actually happens depends on your eviction type setting:
| Eviction Type | What Happens | Disk Preserved? | Can Restart? |
|---|---|---|---|
| Deallocate | VM is stopped and deallocated | Yes | Yes — when capacity available |
| Delete | VM and disk are permanently deleted | No | No — must create new VM |
Maximum Price Setting
You can optionally set a maximum hourly price you're willing to pay for a Spot VM. If the Spot price rises above this, the VM is evicted.
- Setting max price to -1 (recommended) means "never evict based on price — only evict if Azure needs capacity." You'll always pay the current market Spot price, whatever it is.
- Setting a specific price (e.g., ₹5/hour) means you get evicted if price exceeds that. Good for strict budget control.
When to Use Spot VMs
Spot VMs are perfect for any workload that can tolerate interruption and restart from where it left off (or start fresh):
| Workload | Why Spot Works |
|---|---|
| Batch data processing | Process data in chunks — restart failed chunks if evicted |
| CI/CD build agents | Build fails → just re-trigger the pipeline on a new agent |
| Video/image rendering | Rendering jobs can be saved and resumed |
| Machine learning training | ML frameworks support checkpoint saves — resume from last checkpoint |
| Dev/test environments | Occasional interruptions acceptable for non-production |
| Web crawlers / scrapers | Stateless — just restart and continue |
| HPC simulations | Checkpointing allows continuation after interruption |
When NOT to Use Spot VMs
| Workload | Why Spot Fails |
|---|---|
| Production web servers | Eviction causes user-facing downtime |
| Databases | Eviction can cause data corruption or loss |
| Primary application servers | Eviction breaks the application for users |
| Anything with SLA commitments | No SLA on Spot VMs — eviction can happen anytime |
Handling Eviction Gracefully
Azure gives you a 30-second eviction notice via the Azure Scheduled Events service. Your application can poll this endpoint and react — save progress, drain connections, write checkpoints.
# Poll the Azure metadata service for scheduled events
# Run this in a loop inside your application
curl -H "Metadata:true" \
"http://169.254.169.254/metadata/scheduledevents?api-version=2020-07-01"
# If you see "Preempt" in the response, eviction is imminent
# Save your work immediately!
Spot VMs in Scale Sets
VM Scale Sets support a mix of regular and Spot VMs — called Mixed Instance Policy. You can configure Scale Sets to use Spot VMs for most instances (cheap) and a few regular VMs as a baseline (always available). This gives you massive cost savings with some baseline availability.
Creating a Spot VM
az vm create \
--resource-group myResourceGroup \
--name mySpotVM \
--image Ubuntu2204 \
--size Standard_D4s_v5 \
--priority Spot \
--eviction-policy Deallocate \
--max-price -1 \
--admin-username azureuser \
--generate-ssh-keys \
--location centralindia