Introduction:
If you are running workloads on Amazon EKS (Elastic Kubernetes Service), you have probably looked at spot instances to bring the AWS bill down. A lot of teams use them for this. We use them on client clusters as well, and in this post we will talk about the problems we have seen with spot instances in production and what we changed after one of them caused an outage.
What are spot instances?
Spot instances are EC2 instances that AWS sells from its unused capacity at a discount. You get the same servers as on-demand, just cheaper. The catch is that AWS can take the instance back whenever it needs that capacity, and you only get a couple of minutes of notice before that happens.
Risks of using spot instances in production
Cost savings with spot are good, but if you run production on them without planning for it, these are some things that can go wrong.
1. Unpredictable termination
AWS gives a two-minute warning before it reclaims a spot instance. This does not happen with On-Demand or Reserved Instances. If your application doesn’t have another replica running somewhere else or some failover in place, two minutes later your users can start seeing errors.
2. Service downtime
If a workload is running with a single replica, or it can’t scale out in time, then losing the node means the service is down. It will stay down till a new instance is provisioned and the service is deployed on it again.
3. PodDisruptionBudget (PDB) enforcement
In Kubernetes we usually set a PodDisruptionBudget to control how many pods can be disrupted at a time. A PDB can’t stop AWS from reclaiming a spot instance. A termination handler (AWS Node Termination Handler, or Karpenter’s interruption handling) can cordon and drain the node within the two-minute notice and respects your PDBs while it does, but once the notice runs out the node is gone. Any pods the PDB kept from moving go down with it, and for a critical application that can mean an outage. We found this out the hard way, more on that in the incident below.
4. Delayed recovery
AWS will launch a replacement spot instance on its own, but there is no guarantee on when. If there is no spare spot capacity for your instance types or Availability Zones at that time, getting a new node can take much longer than usual and the service stays down for that whole time.
5. Data loss
When the instance goes, whatever was on its local disk (ephemeral storage) goes with it. So don’t keep anything there that you need later. Keep writing it to persistent storage like Amazon EBS, S3 or an external database.
Real world incident: spot instance termination in production
On October 23, 2024, at 7:36 AM IST, we got reports from users that a critical feature was unavailable. This feature relies on XYZ-service, the main service responsible for communication with multiple dependent services. We found that the service had restarted, and the reason was that its underlying spot instance was terminated by AWS.
Normally we would get a new spot instance in about 3 mins. In this case it didn’t come for a long time, so the downtime went on much longer. After this we were not sure we could predict how long recovery would take in such outages.
What we realized is that if you rely only on spot instances, you cannot control how long an outage lasts, because there is no guarantee on how quickly a new spot node will be allocated.
PodDisruptionBudgets (PDB) did not help here either. We had them, but as mentioned above, a PDB can’t keep a spot instance alive past its two-minute notice.
Impact on service availability:
Because of all this, the service was unavailable till the new spot node came up and the pod was scheduled on it. To avoid this in the future, these are the practices we now follow:
Identify critical services and run them on On-Demand instances, which AWS doesn’t reclaim. Savings Plans and regional Reserved Instances only lower the price; if you need capacity guaranteed too, use zonal Reserved Instances or On-Demand Capacity Reservations.
For medium priority services which can handle minor degradation, configure Karpenter to have a mix of on demand and spot instances.
Monitor the ratio of On-Demand to spot instances across all services.
Educate the customer on the cost v/s risk factors for Spot instances so that these resiliency decisions can be baked in earlier in the deployment cycle.
Conclusion:
Spot instances do save money, but for production you need to configure them carefully. Have an on-demand fallback, run more replicas, put monitoring in place so you know when nodes go away, and work on your failover. With these you can keep most of the cost savings without giving up availability. For us it took this incident to make these changes in our infrastructure, and we are now better prepared for the next time AWS takes a spot node back.
Introduction:
If you are running workloads on Amazon EKS (Elastic Kubernetes Service), you have probably looked at spot instances to bring the AWS bill down. A lot of teams use them for this. We use them on client clusters as well, and in this post we will talk about the problems we have seen with spot instances in production and what we changed after one of them caused an outage.
What are spot instances?
Spot instances are EC2 instances that AWS sells from its unused capacity at a discount. You get the same servers as on-demand, just cheaper. The catch is that AWS can take the instance back whenever it needs that capacity, and you only get a couple of minutes of notice before that happens.
Risks of using spot instances in production
Cost savings with spot are good, but if you run production on them without planning for it, these are some things that can go wrong.
1. Unpredictable termination
AWS gives a two-minute warning before it reclaims a spot instance. This does not happen with On-Demand or Reserved Instances. If your application doesn’t have another replica running somewhere else or some failover in place, two minutes later your users can start seeing errors.
2. Service downtime
If a workload is running with a single replica, or it can’t scale out in time, then losing the node means the service is down. It will stay down till a new instance is provisioned and the service is deployed on it again.
3. PodDisruptionBudget (PDB) enforcement
In Kubernetes we usually set a PodDisruptionBudget to control how many pods can be disrupted at a time. A PDB can’t stop AWS from reclaiming a spot instance. A termination handler (AWS Node Termination Handler, or Karpenter’s interruption handling) can cordon and drain the node within the two-minute notice and respects your PDBs while it does, but once the notice runs out the node is gone. Any pods the PDB kept from moving go down with it, and for a critical application that can mean an outage. We found this out the hard way, more on that in the incident below.
4. Delayed recovery
AWS will launch a replacement spot instance on its own, but there is no guarantee on when. If there is no spare spot capacity for your instance types or Availability Zones at that time, getting a new node can take much longer than usual and the service stays down for that whole time.
5. Data loss
When the instance goes, whatever was on its local disk (ephemeral storage) goes with it. So don’t keep anything there that you need later. Keep writing it to persistent storage like Amazon EBS, S3 or an external database.
Real world incident: spot instance termination in production
On October 23, 2024, at 7:36 AM IST, we got reports from users that a critical feature was unavailable. This feature relies on XYZ-service, the main service responsible for communication with multiple dependent services. We found that the service had restarted, and the reason was that its underlying spot instance was terminated by AWS.
Normally we would get a new spot instance in about 3 mins. In this case it didn’t come for a long time, so the downtime went on much longer. After this we were not sure we could predict how long recovery would take in such outages.
What we realized is that if you rely only on spot instances, you cannot control how long an outage lasts, because there is no guarantee on how quickly a new spot node will be allocated.
PodDisruptionBudgets (PDB) did not help here either. We had them, but as mentioned above, a PDB can’t keep a spot instance alive past its two-minute notice.
Impact on service availability:
Because of all this, the service was unavailable till the new spot node came up and the pod was scheduled on it. To avoid this in the future, these are the practices we now follow:
Identify critical services and run them on On-Demand instances, which AWS doesn’t reclaim. Savings Plans and regional Reserved Instances only lower the price; if you need capacity guaranteed too, use zonal Reserved Instances or On-Demand Capacity Reservations.
For medium priority services which can handle minor degradation, configure Karpenter to have a mix of on demand and spot instances.
Monitor the ratio of On-Demand to spot instances across all services.
Educate the customer on the cost v/s risk factors for Spot instances so that these resiliency decisions can be baked in earlier in the deployment cycle.
Conclusion:
Spot instances do save money, but for production you need to configure them carefully. Have an on-demand fallback, run more replicas, put monitoring in place so you know when nodes go away, and work on your failover. With these you can keep most of the cost savings without giving up availability. For us it took this incident to make these changes in our infrastructure, and we are now better prepared for the next time AWS takes a spot node back.
Share
Share
On this page
In this post
section
Share
Related Content

Kong API Gateway for Gaming and Sports Betting Integrations

Modernising Observability for a Billion Dollar Revenue Gaming Platform

Migrating from AWS Glue to Self-Hosted ClickHouse: 70% Cost Reduction for a Fintech Client.

How we reduced Kafka message latency by 90% and increased throughput 4x for a $300M SaaS platform.

















