Open In App

AWS EC2 On Demand and Spot Instances

In this article, we are going to understand difference between EC2 On demand and Spot instances. We are going to learn their usage and working. it is important to understand the difference between AWS EC2 On Demand and Spot Instances so that you can choose right instances for your business requirement.

AWS EC2 (Elastic Compute Cloud) is a cloud computing service that provides scalable compute resources in the cloud. AWS provides these server called EC2 instances for compute purpose or to host your applications. It is  reliable, scalable infrastructure on demand. which provides scale capacity within minutes.



Amazon EC2 Provides the Four Purchasing Options for Instances

  1. On-Demand Instances
  2. Savings Plans
  3. Reserved Instances
  4. Spot Instances
     

We are going to understand the  On Demand and Spot Instances two pricing models that allow customers to pay for EC2 instances in different ways.

On Demand

In this purchasing option you pay for compute capacity by the second with no long-term commitments. You have full control over the instance’s lifecycle—you decide when to launch, stop, hibernate, start, reboot, or terminate it. You don’t need to do  long-term commitment when you purchase On-Demand Instances. You pay only for the seconds which is for when  Instances are in the running state at least  60-second minimum. The price per second for a running On-Demand Instance is fixed. On Demand, customers can launch EC2 instances of  different sizes and only pay for the compute resources they use, without any upfront costs or long-term commitments. However, prices for On Demand instances can be higher than other pricing models, and customers may not have guaranteed capacity or reserved instances in case of AWS failures or disasters.



Working
When instances of different sizes when launch using On Demand different customers will use the shared pool  of EC2 hosts. When any customer launch EC2 instance it will share the same pool of underlying hardware. As resources are shared so prices are reasonable.

Usage

EC2-Spot

As per AWS Spot Instance  uses spare EC2 capacity that is available for less than the On-Demand price. As Spot Instances provide you unused EC2 instances at steep discounts, you can lower your Amazon EC2 costs significantly. The hourly price for a Spot Instance is called a Spot price. Your Spot Instance can  runs whenever capacity is available. Spot Instances mainly used for cost-effective purpose. When you are  flexible about  your applications run and if your applications can be interrupted. Spot Instances are used mostly  for data analysis, batch jobs, background processing, and optional tasks.

Working:

Suppose 4 ec2 instance are running on two ec2 host. However, these host have more capacity means there can be extra ec2 instances which can be hosted. AWS sells this unused capacity EC2 Host capacity for up to 90% discounts. The spot price is based on  the spare capacity at a given time.

In AWS within each region for each type of instance there is a given amount of free capacity on EC2 hosts at any time. AWS tracks this. it publishes a price for how much it costs to use that capacity and this price is the spot price. It is up to you to offer spot price you can pay more or less quoting specified price but you will be charge only specified spot price(you will be charge only that spot price which  spot price aws has mentioned ).

In case AWS demand EC2 host need more capacity and AWS is running low so they will try to increase the spot price. In that scenario the customer who have setup more spot price will remain or can keep his spot instances however, customer who have offered less spot price his instances will be terminated.

Now for above situation suppose AWS had proposed 1 rupee(just an assumption AWS doesn’t offered in rupee)  as spot price. Customer A booked for 1 rupee sot price however, Customer B offered 2 rupees for spot instances. In this scenario both will be charged 1 rupee but in case On demand capacity requires more in that case AWS has to terminate the  spot instance. IN that scenario AWS will increase the spot price to 2 rupees. Customer A spot instance will be terminated however,

customer B instance will remain as he offered the 2 rupees spot price. 

spot instances

In below diagram customer A instance will be terminated and will be used for On demand instances.

Spot Instances

Usage

Spot instance should not be relied. They can be used for scientific research or where workload can be interrupted. Spot instance can not be used for domain controllers, mail servers traditional websites or flight system. Spot instance can be used for following purpose:

Best Practices

EC2 On demand can be used when you do not want to interrupt your application. You are not sure about the time  and unsure about workloads then use OnDemand.

EC2 Spot instances when you are flexible enough that your application can be interrupted or your application is stateless. You need a cheaper solution for compute resources.

Conclusion

EC2 On demand is pay as you go basis. You pay for per second basis. You are not sure your application is for long term or short term. In case  you need cheapest option, and you are flexible enough for your instance termination at any time use spot.

Article Tags :