Can you use Spot Instances inside an Auto Scaling group, and how do you do it safely?
Yes. A mixed instances policy lets an ASG combine On-Demand and Spot across several instance types. Keep a small On-Demand base, spread Spot across types and AZs, and make the app handle the two-minute interruption notice.
Explain it simply
It is like hiring extra delivery riders on a festival weekend. Permanent riders (On-Demand) always show up. Gig riders (Spot) are cheaper but can be called back at short notice, so you only give them jobs that can be handed over safely.
Example
ASG mixed instances policy
On-Demand base capacity : 2 instances (always)
Above base : 20% On-Demand, 80% Spot
Instance types : m5.large, m5a.large, m4.large, c5.large
Allocation strategy : price-capacity-optimized
Subnets : AZ a, b, c
On interruption notice (2 minutes):
- stop taking new work
- finish or checkpoint current job
- deregister from load balancerUsing many instance types and AZs lowers the chance that all Spot capacity disappears together. Capacity Rebalancing can launch a replacement when AWS signals an instance is at elevated risk of interruption.
Good Spot workloads are stateless web tiers, batch jobs, CI runners and data processing. A single database or any job that cannot be restarted is a poor fit.
What to say in the interview
"Yes, through a mixed instances policy: a small On-Demand base for stability, Spot above that, spread over several instance types and AZs. The app must be stateless or checkpointed so it can handle the two-minute interruption warning."
Common mistakes
- Choosing only one instance type for Spot, which makes interruptions correlated.