What is a Spot Instance?
A spot instance is nothing but spare compute capacity in the cloud that you can bid for. Usually these instances are available at a cheaper price than the On-Demand instances. Spot instances are available on various cloud platforms such as AWS, Azure, etc. These instances are nothing but regular on-demand instances but with different billing approach.
Some concepts :
- Spot price: Current price of Spot instance per hour.
- Spot Instance request price: The maximum price a customer is willing to pay for a Spot instance per hour. Once the maximum price exceeds spot price, Amazon EC2 will fulfil your request if capacity is available.
- Spot Instance Pool: Same types of group of instances (OS, size, network, etc) which are unused.
Let's consider an example :
You bid $1.50 for a spot instance & the current Spot price is $1.20 then you have successfully bid for that instance.
Some things to keep in mind :
- If we terminate our instance that we bid on, we still pay for the full hour for that spot instance, in our example, it will be $1.50 / hr.
- If Amazon terminates our instance then we get that entire hour for free! that is 0$ ( and not $1.50). Note that this price is an hourly basis, So if you used the Spot instance for 1hr 30 minutes and amazon terminates your spot instance at 1hr 31 min mark, then you still have to pay for the first hour ( $1.50) but the 30 minutes you don't have to pay anything.
- Spot instances are Hibernated / Terminated when the required capacity is no longer available with prior 2-minute notification. Amazon also terminates your spot instances if the Spot price goes higher then User requested Spot instance price.
- Its recommended that the processes use S3 or blob storage for data when using spot instances.
When to use Spot instances?
- Where storage is minimal or temporary
- Where the data related workloads are quickly done
- Complex and large but quick processing to be done at cheaper rates. For example, a company needs to do some complex image processing for which they require a large amount of computing power. They can easily request 100's of spot instances and not worry about the huge cost of normal (on-demand) 100 instances & get their work done quickly and cheaply
- Small proof-of-concepts
- Where applications have flexible start and end times
Where not to use Spot instances?
- Spot Instances are not meant to be used for mission-critical workloads.
- Where there are long-running processes
- For real-time applications or fetching data from external sources.
For a spot instance you don’t pay the bidding price, you pay the current spot price. The bidding price is the cutoff point. If the current spot price exceeds that of the bidding price AWS will terminate that instance.