AWS EC2 Spot Instances Explained: Savings, Risks, Uses
EC2 Spot Instances are spare AWS compute capacity sold at up to 90% less than on-demand pricing. In exchange for the discount, AWS can reclaim the instances with a 2-minute warning. Used with the right architecture, Spot Instances can cut a compute bill dramatically, without sacrificing reliability.
Simple explanation
AWS runs data centres with more physical capacity than its on-demand customers are currently using. Rather than leave that spare capacity idle, AWS rents it out at a steep discount. These are Spot Instances.
The trade-off is that the capacity is not guaranteed. If AWS needs it back for an on-demand customer, it reclaims your instance with a 2-minute warning. That makes Spot unsuitable for anything that must stay running. It is ideal for work that can be paused, retried, or spread across many short-lived machines.
Good example: a batch job that processes 1,000 video files. Each file is independent. If an instance is interrupted mid-file, you reprocess that one file on another instance. Your total cost on Spot might be $30 instead of $200.
A production database that must stay up for customers. An interruption means downtime. Use a reliable On-Demand EC2 Instance for that. Spot is the wrong tool for stateful, always-on systems.
How Spot Instances work
Each AWS Availability Zone maintains a pool of capacity for each EC2 instance type. When on-demand and reserved customers are not using all of it, the remainder becomes available as Spot.
The Spot price fluctuates based on supply and demand in each AZ for each instance type. AWS publishes historical pricing so you can see how stable a given instance type tends to be in a given zone. In practice, most pools are stable. Large sudden price spikes are rare.
AWS retired the old bidding model in 2017. You no longer submit a bid price. Instead, you set a maximum price (which defaults to the on-demand price if you leave it unset). Your instance keeps running as long as the current Spot price is below your maximum and AWS has not reclaimed the capacity.
In most real interruptions, the reason is that AWS needs the capacity for on-demand demand, not because the price exceeded your threshold. This means diversifying across instance types and AZs matters far more than tuning your maximum price.
Check current and historical Spot prices with: aws ec2 describe-spot-price-history —instance-types m5.large —product-descriptions “Linux/UNIX”. A stable price history in an AZ is a good signal of low interruption risk for that instance type.
How interruptions work
When AWS needs to reclaim Spot capacity, it sends a 2-minute interruption notice through two channels:
- Instance metadata endpoint:
http://169.254.169.254/latest/meta-data/spot/interruption-noticereturns the scheduled interruption time once a notice has been issued. Poll this endpoint every 5 seconds from your application or a sidecar process. - EventBridge event: AWS publishes an
EC2 Spot Instance Interruption Warningevent to EventBridge. You can route this to a Lambda function, SQS queue, or SNS topic to trigger graceful shutdown logic from outside the instance.
In those two minutes, a well-designed application should: stop accepting new connections, finish any in-flight requests, drain from the load balancer target group, save any checkpoint state to S3 or a database, and exit cleanly.
After the notice period, AWS stops, terminates, or hibernates the instance depending on the interruption behaviour you configured. For stateless applications, terminate is the right default. For resumable jobs, stop or hibernate preserves work in progress so the job can continue when the instance restarts elsewhere.
Rebalance recommendations
Before the 2-minute interruption notice, AWS may send an EC2 Instance Rebalance Recommendation signal. This arrives when an instance is at elevated risk of interruption. The Spot pool it is running in is becoming constrained. The rebalance recommendation does not guarantee an interruption is coming, and it does not start the 2-minute clock. But it gives your infrastructure more lead time to act.
The right response is to enable Capacity Rebalancing in your Auto Scaling Group. When Capacity Rebalancing is on, the ASG listens for rebalance recommendations and proactively launches a replacement instance from a healthier Spot pool, only terminating the flagged instance once the replacement is in service. This keeps your fleet size stable and avoids a sudden multi-instance loss when a whole pool tightens.
An instance can receive a rebalance recommendation and never actually be interrupted. AWS may restore capacity in that pool. Even so, proactive replacement is a safer default than waiting for the 2-minute clock. Enable Capacity Rebalancing in every production Spot ASG.
Analogy
Spot Instances are like standby airline seats. You get a steep discount because the seat would have flown empty anyway. But the airline can bump you if a full-fare passenger needs it. If you are flying to a wedding you cannot miss, buy a regular ticket. If you are flexible and can catch the next flight, standby is a great deal. Just do not make firm plans that depend on it.
How to run Spot safely in production
The standard production pattern is a mixed-instance Auto Scaling Group: a guaranteed base of On-Demand instances for reliability, plus a larger share of Spot instances for cost savings. You configure this with a launch template and a mixed instances policy.
Three practices make Spot reliable at scale:
- Diversify instance types. Include at least 4–6 instance types with similar CPU and memory profiles (for example: m5.large, m5a.large, m4.large, t3.large, t3a.large). If one pool is interrupted, the ASG launches from another type automatically.
- Spread across multiple AZs. Spot interruptions are AZ-specific. A capacity crunch in a single AZ can take down your entire fleet at once. Always spread across at least two AZs using multiple subnet IDs in your ASG configuration.
- Keep an On-Demand base. Always run a minimum number of On-Demand instances so you have guaranteed capacity even if all Spot pools are temporarily unavailable. Two is a common minimum for a web tier.
Use the price-capacity-optimized allocation strategy. This is AWS’s current recommended default. It selects Spot pools with the best combination of capacity depth and low price, reducing both interruption frequency and cost. The older capacity-optimized strategy is still valid but prioritises availability only. Start with price-capacity-optimized for most workloads.
aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name mixed-spot-asg \
--mixed-instances-policy '{
"LaunchTemplate": {
"LaunchTemplateSpecification": {
"LaunchTemplateName": "web-server-template",
"Version": "$Latest"
},
"Overrides": [
{"InstanceType": "m5.large"},
{"InstanceType": "m5a.large"},
{"InstanceType": "m4.large"},
{"InstanceType": "t3.large"},
{"InstanceType": "t3a.large"}
]
},
"InstancesDistribution": {
"OnDemandBaseCapacity": 2,
"OnDemandPercentageAboveBaseCapacity": 20,
"SpotAllocationStrategy": "price-capacity-optimized"
}
}' \
--capacity-rebalance \
--min-size 2 \
--max-size 20 \
--desired-capacity 6 \
--vpc-zone-identifier "subnet-abc,subnet-def,subnet-ghi"What this configuration does:
- Keeps at least 2 On-Demand instances running at all times (
OnDemandBaseCapacity) - Runs 80% of any capacity above that base on Spot, 20% on On-Demand
- Uses
price-capacity-optimizedto balance interruption risk and cost - Enables
—capacity-rebalanceso the ASG proactively replaces at-risk Spot Instances before they are terminated - Tries 5 instance types so there are always fallback options if one pool is exhausted
Pair this with a well-tuned autoscaling policy to keep your fleet right-sized as load changes throughout the day.
When to use Spot Instances
Spot Instances work well when your workload is stateless or checkpointable, can retry failed units of work, and is not on the critical path for real-time user requests.
- Batch processing: ETL jobs, log processing, image and video transcoding, report generation. Each unit of work is independent. An interrupted instance just re-queues its items.
- CI/CD build runners: Jenkins workers, GitHub Actions runners, and similar agents that run a job and exit. A failed build retries. It is not a service outage.
- Stateless web tiers: API servers behind an Application Load Balancer. If an instance is interrupted, the load balancer stops routing to it and the ASG launches a replacement. With sufficient On-Demand base capacity, this is invisible to users.
- ML training and distributed data processing: Frameworks like PyTorch and TensorFlow support checkpointing, saving model state periodically so a job can resume from the last checkpoint after an interruption rather than starting from scratch.
- Dev and test environments: Non-critical environments that can tolerate a restart and do not need to be running around the clock.
When not to use Spot Instances
If your workload cannot survive a sudden 2-minute shutdown notice, do not use Spot. The discount is only worth it when your architecture is genuinely prepared for interruption.
- Single-instance databases: A 2-minute notice is not long enough to safely flush and close a database. If you have no replica and the instance is terminated, that data is at risk. Do not run a primary database on Spot without robust replication and a tested failover plan.
- Tightly stateful systems: Applications that store state in memory or local disk without replication. Game servers with live sessions, single-node message brokers, and distributed locks will all lose that state when the instance is replaced.
- Latency-sensitive real-time workloads: If a sudden drain window of up to 2 minutes causes user-visible errors, or if your workload depends on a specific instance staying up, On-Demand is the right answer.
- Anything that cannot handle sudden replacement: Some software breaks when its host disappears mid-operation. Third-party SaaS agents, licence servers, and legacy applications with hard-coded hostnames are common examples. Test carefully before using Spot, and default to On-Demand when in doubt.
Spot vs On-Demand vs Reserved Instances and Savings Plans
There are four main ways to pay for EC2 compute. Each suits a different situation. See the AWS billing guide for a full breakdown of how charges appear in your bill.
| Option | Relative cost | Interruption risk | Best for | Not suitable for |
|---|---|---|---|---|
| Spot | Up to 90% below On-Demand | High; reclaimed with 2-min notice | Batch jobs, CI/CD runners, stateless web tiers, ML training | Databases, stateful workloads, real-time services |
| On-Demand | Full price, no commitment | None | Variable workloads, short-lived jobs, guaranteed production baseline | Long-running steady-state capacity (expensive over time) |
| Reserved Instances | 30–60% below On-Demand with 1 or 3-yr term | None | Steady-state production workloads with predictable capacity needs | Workloads with variable or uncertain size |
| Savings Plans | Similar savings to Reserved, more flexible | None | Teams with consistent compute spend who want flexibility across instance families | Workloads needing maximum discount tied to a specific instance type |
In practice, most teams layer all four: Reserved Instances or Savings Plans for the steady-state baseline, On-Demand for variable headroom, and Spot for burst or batch capacity. This gives reliable capacity at a lower average cost than any single option alone.
Common mistakes
- Using only one instance type. If you only request m5.large and that pool is exhausted, the ASG cannot scale. Always specify at least 4–5 instance types with similar specs so there are fallback options across pools.
- Using only one Availability Zone. Spot interruptions are AZ-specific. A capacity crunch in a single AZ can take down your entire fleet at once. Spread your ASG across multiple AZs from the start.
- Not handling the interruption notice. Applications that do not poll the metadata endpoint or listen for EventBridge signals get terminated mid-request with no graceful shutdown. This is entirely avoidable with a small amount of integration work.
- Skipping Capacity Rebalancing. Many teams handle the 2-minute termination notice but do not enable Capacity Rebalancing. Without it, the ASG only reacts after an instance is already being terminated. Enable it so replacements are launched proactively when pools become constrained.
- Treating Spot as guaranteed capacity. Spot is spare capacity. In large-scale demand surges or regional events, entire Spot pools can be unavailable for a period. If you have no On-Demand base, your fleet could shrink to zero. Always keep a guaranteed minimum baseline.
- Using the lowest-price allocation strategy. The cheapest Spot pool is often the shallowest and most likely to be interrupted. Use
price-capacity-optimized, which balances cost with pool depth and is the current AWS-recommended default.
Summary
- Spot Instances use spare AWS capacity at up to 90% off On-Demand pricing. AWS can reclaim them with a 2-minute interruption notice.
- Best suited to stateless, fault-tolerant workloads: batch jobs, CI/CD runners, stateless web tiers, and ML training with checkpointing.
- Diversify across multiple instance types and AZs to reduce the impact of any single pool being interrupted.
- Use the
price-capacity-optimizedallocation strategy to balance interruption risk and cost. - Enable Capacity Rebalancing so your ASG proactively replaces at-risk instances before the 2-minute termination clock starts.
- Always keep an On-Demand base so minimum capacity is guaranteed even if all Spot pools are temporarily unavailable.
- Handle interruption signals via metadata polling or EventBridge to enable graceful draining of connections and state.
Frequently asked questions
What are EC2 Spot Instances?
Spot Instances are spare EC2 capacity that AWS sells at up to 90% less than on-demand pricing. AWS can reclaim them with a 2-minute warning when it needs the capacity back. They are best suited to stateless, fault-tolerant workloads such as batch jobs, CI/CD runners, and ML training with checkpointing.
How much notice do I get before a Spot Instance is interrupted?
AWS sends a 2-minute interruption notice via the instance metadata endpoint and an EventBridge event. A rebalance recommendation can arrive even earlier. It signals that the instance is at elevated interruption risk, giving you a chance to replace it proactively before the 2-minute clock ever starts.
Can Spot Instances be used in production?
Yes, with the right architecture. The standard pattern is a mixed-instance Auto Scaling Group: a base of On-Demand instances for guaranteed capacity, plus a larger share of Spot for cost savings. Your application must be stateless and must handle the interruption notice gracefully.
What is the difference between Spot and On-Demand Instances?
On-Demand Instances run until you stop or terminate them and are billed at the full hourly rate with no interruption risk. Spot Instances use spare AWS capacity at a steep discount but can be reclaimed by AWS with 2 minutes notice. Use On-Demand for anything that cannot tolerate interruption; use Spot for fault-tolerant workloads where cost matters.
What is Capacity Rebalancing?
Capacity Rebalancing is an Auto Scaling Group feature that monitors for EC2 Instance Rebalance Recommendation signals and proactively launches a replacement Spot Instance from a healthier pool, before the 2-minute termination notice arrives. Enabling it reduces the chance of sudden fleet-wide capacity loss during a Spot crunch.