At Mobilise we’re always looking at ways to innovate and pass on savings to our customers, our most recent foray into spot instances aims to do just that. This blog will describe how, through the use of AWS Spot Instances and a piece of software called SpotInst, you can save up to 80% on your AWS Compute costs.
What are spot instances?
So, you’re most likely used to running the standard EC2 instance type ‘On Demand’ which has a standard pricing model whereby you pay a fixed rate per second that the instance is running.
Amazon also offer another two pricing models; Reserved and Spot. Reserved lets you purchase an instance for a set period of time e.g. 3 years with a discounted rate of up to 75% but ties you in to a long commitment. This type of pricing model works well if you’ve got production instances to support that you know the shelf life of, but what happens if you want to run an unspecified number of non-production instances?
How can you forecast how many reserved instances you need to purchase for the next year? What happens if your project gets canned and you’re left paying for instances you’re not going to use? This is where Spot Instances come into play!
Spot Instances take advantage of spare compute power that Amazon is not using, essentially EC2 instances that are sitting idle. Amazon offers these spot instances at a massively discounted rate – up to 90% off the on-demand price!
Okay – so what’s the catch?
Sound a little too good to be true? Amazon don’t offer this huge discount without a couple of caveats…
The price of a spot instance is determined by the spot market; if a particular instance type e.g. T2.Medium is in more demand than usual then the spot price for that instance is more expensive, where as if a M5.XLarge instance type isn’t being actively used by the market, the spot price is cheaper. When creating your spot instance, you specify the maximum amount you are willing to pay for the instance – the default is the on-demand price.
Your spot instance will be stopped by Amazon if:
- Amazon need the unused compute power back
- Your set spot price exceeds the market spot price
Amazon will give you a two-minute warning before it stops your instance, so you need to design your application to handle interruptions and also design the infrastructure around this. Furthermore, Amazon doesn’t guarantee this warning and states it is possible your instance is stopped before this warning ever reaches your spot instance.
This means you’re going to need to make design choices on things like;
- Do you store everything in S3 so that new spot instances can carry on where the old stopped spot instances left off?
- Do you keep your data on EBS volumes and ensure they’re detached from stopped spot instances and attached to the new spot instance?
- What if all of the spot instances are taken in AZ1, has your infrastructure been designed to scale across AZ2 & AZ3?
This work requires a lot of automation and could turn into a full-time job for a team to manage a large fleet of spot instances.
So, who are spot instances for?
Well, you know all of that design and implementation you would have to do to keep your normal workloads up and running all of the time – someone has done that for you, and they’re called SpotInst.
SpotInst will manage your spot instance for you by connecting to your AWS account and managing things like Auto Scaling Groups to stop & start instances. They use algorithms to determine the likelihood of Amazon stopping a spot instance based on statistical and historical data and automatically scale up a new instance type before that happens to ensure zero downtime.
SpotInst integrate with existing AWS Load Balancers to ensure a smooth transition of traffic whilst also integrating with BeanStalk, EMR & CodeDeploy. SpotInst has taken the fear out of using spot instances by implementing a dependable set of algorithms and seamless integration.
One of the biggest advantages for Mobilise was to use SpotInst with Kubernetes. The SpotInst Kubernetes agent allows you to run workloads on spot instances with no interruption to service. Workloads are migrated gracefully from one stopping spot instance to a new spot instance with zero downtime. Mobilise now run all of their internal Kubernetes workloads on EKS with SpotInst and we have saved around 60% on our monthly cluster costs.
And that’s not all…SpotInst provide Terraform & CloudFormation support so you can create your spot instances using Infrastructure As Code. This allows you to create extremely cheap, reliable, repeatable environments with little effort and a happy DevOps team who don’t have to manage the lifecycle of spot instances. Although this blog has been focused on AWS, this is also possible on Microsoft Azure and the Google Cloud Platform.