An AWS spot instance is an unused EC2 instance, which Amazon sells at a lower price on its spot market. Spot instances are up to 90% cheaper than on-demand instances, which can have a major impact on your Amazon EC2 bill. Spot instances are an important AWS cost optimization technique.
The hourly rate for a spot instance is known as a Spot price. Amazon determines the spot price of every instance type in every availability zone, gradually adjusting it according to long-term supply and demand. Amazon starts your spot instance if it has available capacity, and your bid price exceeds the current spot price for that instance type.
To utilize spot instances, you create a sport instance request that defines:
The instance type
The required number of instances
The availability zone
The uppermost price you wish to pay per instance hour (bid price)
If the bid price goes above the current spot price, Amazon EC2 carries out your request immediately, as long as there is available capacity. Alternatively, Amazon EC2 waits until you cancel your request or until the spot price goes down.
There are two types of spot requests:
A one-time spot request stays active until Amazon EC2 runs the spot instance, you cancel the request, or it expires. If the spot price goes above your bid or capacity is unavailable, Amazon terminates the spot instance and closes the spot request.
A persistent spot instance request stays active until you cancel it or until it expires—even if Amazon carried out the request. If the spot price goes above your bid or capacity becomes unavailable, the spot instance is interrupted. Amazon keeps the request open, and if conditions change and a spot instance does become available, it starts or resumes the spot instance.
In both cases, when a spot instance is terminated, Amazon gives you five minutes’ notice to clear workloads from the EC2 instance. After that time, the instance is destroyed or paused, depending on your settings.
Spot Instance Limitations
You can spot instances as long as EC2 instances are available on the spot market at your bid price. A major challenge with spot instances is that the AWS spot market is volatile. Amazon prices spot instances according to Amazon region and instance type, and the specific combination of instances you need can run out at any time.
In addition, even if spot instances are available when you need them, they can be terminated abruptly if the spot price rises above your bid. If you don’t have a way to switch workloads to another instance quickly, you can experience data inconsistency, data loss, and interruption of active user sessions.
Estimating Spot Instance Costs with the AWS Calculator
The spot instance advisor calculator lets you discover which pools will have the lowest likelihood of interruption and offers the savings you receive over on-demand rates. You should consider your application’s tolerance for interruptions and your budget aims when choosing a Spot instance. Your Spot instances will probably run longer if you have a lower interruption rate.
AWS suggests beginning with instance types that are less likely to be interrupted and adding a wider variety of instance types as you work on your application’s fault tolerance and flexibility.
The average likelihood of interruptions overall instance types and Regions is <10%.
Is Your Application Spot-Ready?
Not every application is suitable for spot instances. To identify if your application is a good candidate, answer the following questions:
How long does it take the application to complete a task? If tasks are short and independent of each other, the application is suitable for spot instances.
Do critical business processes depend on the application? The less critical the application, the more suitable it is for spot instances.
Is the application able to gracefully withstand interruptions? If so, it is more suitable for spot instances.
Are nodes tightly coupled? If each node operates independently of other nodes, the application is a good candidate for spot instances.
What is your strategy for shifting workloads when AWS terminates a spot instance?
If you determine that your workload is a good candidate for spot instances, here are some tips to help you out:
When selecting spot instances, try to pick unpopular regions and instance types—this will lower the chance that instances will be requested by others, improving reliability.
See how often instances were interrupted in the preceding period. You can see this data in AWS Spot Instance Advisor, shown below.
It is possible to use spot instances for critical workloads that cannot withstand interruption. AWS offers special spot instances that guarantee up to 6 hours of uptime. These are more expensive, but still grant a discount of 30-50%.
Use capacity rebalancing, an Amazon feature that helps maintain workload availability. Capacity rebalancing can automatically add instances to your EC2 auto-scaling groups, even before the spot instance receives its 2-minute termination notice. This reduces the risk of interruption.
Leverage AWS Spot Fleet, an Amazon feature that lets you request multiple instance types at the same time, to increase the chance that at least one is available. Spot Fleet allows you to manage scalability using multiple spot instance categories, and combine spot instances with on-demand instances in the same auto-scaling group.
How Much Can You Really Save with AWS Spot Instances?
The major attraction of AWS spot instances is that they can save up to 90% compared to on-demand instance costs. However, spot instances have limitations and peculiarities you need to deal with, reducing your effective saving.
Here are a few hidden costs of AWS spot instances, which you must take into account before using them in your applications:
Cost of downtime—even if your applications can transition to another instance when a spot instance terminates, this will not always work perfectly. Errors will result in service disruption, which has a cost for your organization.
Cost of automation—in most cases, you will need to develop automated mechanisms to manage provisioning and scaling of applications on spot instances. Automation has a high cost—you need to develop it, monitor the performance of automated mechanisms, and troubleshoot problems.
Cost of sub-optimal instance types—because you rely on spot market fluctuations, you will sometimes need to choose instance types that do not suit your application. For example, assume your application requires high-powered instances but these are not available on the spot market. You’ll need to use instances with less CPU and memory resources, and application performance will suffer.
Lack of predictability—spot instances provide lower costs but are also less predictable. They will sometimes be unavailable, and the cost can differ depending on market forces. This lack of predictability makes it more difficult to plan budgets and allocate resources, and in the end, creates an additional cost to the organization.
Spot instances are an exciting innovation and one that any organization using the cloud should consider. Consider the hidden costs listed above. Make sure you understand the full financial impact of spot instances and balance all costs to determine if the move is worthwhile.