Everything you needed to know about spot instances.
2 October 2017 • 10 min read • Blog Post
AWS recently announced some more features for Spot instances, an exciting prospect for anyone wanting to make some significant savings. In this blog, we'll take you through what Spot instances are and how they differentiate from Reserved instances.
Spot instances, next to On-demand and Reserved instances are another financial model for your EC2 workloads. With On-demand, you pay a fixed hourly price per instance. With Reserved instances, you're able to reduce your EC2 cost by around 30-40% in exchange for a 1 or 3 year commitment to AWS. While Reserved instances bring you a significant discount compared to On-demand, you are tied into this commitment. If AWS reduces their prices or introduces new instance types that are cheaper, your savings could end up lower and you'll still be paying for your Reserved instances until the end of the commitment.
Spot instances work on a supply and demand model, meaning AWS takes advantage of unused instance capacity, giving you the opportunity to save as much as 90% compared to the On-demand cost.
Let's see how the pricing history looks in an eu-west-1 region fro certain instances:
For the majority of the time, the most popular instances tend to keep their market price significantly below the On-demand price. If you were to run a single Spot instance such as m3.medium in the eu-west-1a availability zone for the previous 3 months, you instance would be running without any interruptions for a whole term, (saving you around 80% compared to the On-demand price).
You could still bid your price around the On-demand price and get the same savings. The problem starts however when you want to use bigger instances (eg. m4.16xlarge). These bigger, more expensive instances tend to exceed the On-demand price, making them a bit riskier. However, over three months in the example below, the m4.16xlarge instance price exceeded the On-demand price only once.
If you choose a more 'unusual' instance, there will be a higher possibility of exceeding the On-demand price.
Let's look at some other examples:
Instances like d2 or g3 fluctuate much more than the 'standard' instances. There's a possibility of saving a considerable amount on these, but you need to be prepared for a sudden stop or termination.
What if you want to run your application on different instance types and recieve optimum savings? The answer to this would be to use Spot fleet.
A Spot fleet is a collection of Spot instances which attempts to maintain the capacity you've specified. For example, when you run your application on a single m4.large On-demand instance, you can use Spot fleet to specify that your application needs to be run on multiple instances.
You can also specify that your desired capacity is 1, meaning you can run on either the m4.large, m4.xlarge, m4.2xlarge etc, as all of them have the same specifications as the m4.large, (you can also choose instances from another family that match your desired instances' parametres). You can then set up your bid price globally for around the same price as the m4.large On-demand price. Spot fleet then attempts to launch the specified instances that will result in the lowest cost. This results in an overall higher ability and can lead to even higher savings. For example, if the m4.large instance price rose over the On-demand price, (some of your other instances in your spot fleet might currently have a lower market price) then your workload will be moved to another instance instead of being stopped or terminated.
So what's the catch?
First, we need to understand how exactly the pricing model for Spots works. When you want to use Spot instances, you submit a Spot request in the EC2 console or using the CLI. Here, you have to specify all parametres of the instance (OS, type, size, availability) and your bid price. The bid price is the maximum price your willing to pay for a specified EC2 instance. When your bid price exceeds the current market price and the instance is available you can use it at the market price. The current market price is given live updates and reflects the need for specific instances. If your bid price is lower than the current market price, you will not get the possibility to use the Spot instance. If you're using a Spot instance and the market price exceeds your bid price, your instance will be terminated or stopped (you'll receive a notification two minutes before it happens). It's good to note here that if the instance is stopped you will still be paying for EBS volumes as usual, but you can terminate or stop your instance at any point, (Spots are different from Reserved instances as they can be stopped at anytime). The way pricing works also means you're not able to forecast your costs and plan your budget with 100% accuracy, however, you can still view a specific instance market price history in the AWS console. In the example below, we're looking at an m4.xlarge instance running in a us-east-1 availability zone, (each AZ has its own market price, compared to On-demand and Reserved instances where price is set on a regional level). Let's say you want to use an m4.xlarge Spot instance in a us-east-1e availability zone. If your bid price was $0.1, (shown on the graph below) the market price would exceed your bid-price, and your instance would be stopped or terminated. However, for the majority of the time you would actually pay around $0.06 per hour, (which would be 70% less that On-demand). Now let's say your bid price was $0.18 (close to the On-demand price). In this case, your instance would be stopped less frequently because the price was only exceeded a few times in a given term. You would still pay around $0.06 for the majority of the time, but because you pay the market price, your bid should only exceed the current market price. You would be saving around 65-70%, even though your bid price was much higher. It's best to bid below the On-demand price, which brings not only savings, but also reduces the risk of your instance becoming inactive. Note: T2 and HS1 instances are not available on the Spot market
Let's see how the pricing history looks in an eu-west-1 region fro certain instances:
For the majority of the time, the most popular instances tend to keep their market price significantly below the On-demand price. If you were to run a single Spot instance such as m3.medium in the eu-west-1a availability zone for the previous 3 months, you instance would be running without any interruptions for a whole term, (saving you around 80% compared to the On-demand price).
You could still bid your price around the On-demand price and get the same savings. The problem starts however when you want to use bigger instances (eg. m4.16xlarge). These bigger, more expensive instances tend to exceed the On-demand price, making them a bit riskier. However, over three months in the example below, the m4.16xlarge instance price exceeded the On-demand price only once.
If you choose a more 'unusual' instance, there will be a higher possibility of exceeding the On-demand price.
Let's look at some other examples:
Instances like d2 or g3 fluctuate much more than the 'standard' instances. There's a possibility of saving a considerable amount on these, but you need to be prepared for a sudden stop or termination.
What if you want to run your application on different instance types and recieve optimum savings? The answer to this would be to use Spot fleet.
A Spot fleet is a collection of Spot instances which attempts to maintain the capacity you've specified. For example, when you run your application on a single m4.large On-demand instance, you can use Spot fleet to specify that your application needs to be run on multiple instances.
You can also specify that your desired capacity is 1, meaning you can run on either the m4.large, m4.xlarge, m4.2xlarge etc, as all of them have the same specifications as the m4.large, (you can also choose instances from another family that match your desired instances' parametres). You can then set up your bid price globally for around the same price as the m4.large On-demand price. Spot fleet then attempts to launch the specified instances that will result in the lowest cost. This results in an overall higher ability and can lead to even higher savings. For example, if the m4.large instance price rose over the On-demand price, (some of your other instances in your spot fleet might currently have a lower market price) then your workload will be moved to another instance instead of being stopped or terminated.
What else can I do with Spot fleets?
You can use instance weighting to specify differences between various instances according to what you need. For example, your application performs best with at least 8GIB of RAM and 2 vCPUs. If you wanted to run one 8GIB plus 2 VCPUs as 1 unit (running 16 of them at a time), and use m4.large as our base unit, here's how the initial list of instances (pools) would look next to a Spot fleet:| Instance Type | RAM (GIB) | vCPU |
| m4.large | 8 | 2 |
| m4.xlarge | 16 | 4 |
| m4.2xlarge | 32 | 8 |
| m4.4xlarge | 64 | 16 |