DEV Community

Cover image for AWS Compute with High Availability & Huge Savings - A simple strategy using Spot !!

AWS Compute with High Availability & Huge Savings - A simple strategy using Spot !!

Welcome folks !! This is another interesting post with simple AWS Architecture diagram explaining an implementation strategy for achieving high availability for Compute(EC2) with great efficiency yet save on money !!

Represented here is a simple illustration but a powerful & transformative approach, if you have a use case involving compute services with varied but predictable demand. Normally, people are under a notion that these kind of compelling use cases have complicated architecture, device, third party tools to achieve such efficiency but with a huge investment for time & cost. Actually, it is challenging but doable with simple concept of introducing Spot EC2 instances as below

Image description
Tried above with Diagram as Code !!

Wait !! Let us get answers to the random Why's that are being popping up at this point :-)

Just use Spot instead of on-demand save cost?
Yes, but not just Spot Instances but spot in combination with on-demand instances does that. Spot cannot be relied on completely as it involves notification & termination at any point in time

When to use this mix of On-demand and Spot instances?
Use spot instances on work loads which are flexible & fault tolerant like dev/sit work, CI/CD runs, Batch Jobs, etc. Spot instances are to be balanced so as not to cause in unavailability of the application or service to end users

How does involving spot instances help in savings?
Well, with the knowing of Spot instances providing unto 90% savings compared to on-demand instances, introducing spot instances with applicable weightage or split between 10 to 60% on Spot, is definitely a winning combo(this may vary with use cases)!!

What attributes to this plan work in reality?
Strategic, data driven planning in the split % of on-demand and spot instances is the key and aids in huge savings !!

Steps involved:

  1. Identify the AWS Region, Create VPC, Public Subnet, IGW, Private Subnets, Route Tables, Security Groups, as needed
  2. We need to define Launch Template, Target Group and later match it to an Application Load Balancer, to make this functional
  3. Use a Launch Template to define the parameters for spot instances. Advantage of having a Launch template in place is that LT can be versioned and re-used later for different requirements without redefining load(s) of parameters
  4. Now raise a 'Spot Fleet Request' using the Launch Template created above. Here in the "Target Capacity" provide the no. of spot instances that you are in need of, on-demand capacity and also whether to replace the interrupted spot instances automatically or not. These are key parameters which lifts this solution to work wonders
  5. Next will be target group to be defined which will bind on-demand and spot instances against the load balancer. Key to make this efficient are i) the parameters defined for health check and ii) mapping on-dem & spot in the target group
  6. Now create an Application Load Balancer, map the target group created above with the ALB (under the Listeners & Routing category)
  7. ALB created above should have a DNS name to work with; Copy the DNS name and try the URL
  8. Now the URL requests will be served with spot & on-demand instances according to the demand & availability

Note: Include a simple script with on-demand & spot instances by installing apache server & echo the 'host name' or 'IP address' for us to understand which server is now serving the request

Simple example comparing the pricing of m5a.xlarge instance

  1. Below is a monthly pricing derivation but look at this at as having 58% of discount for this type of instance at an hourly rate of 0.172/hr against on-demand
  2. From AWS Pricing calculator for a monthly constant usage gives us at a rate of 52.73 monthly
  3. Spot isn't said to be available all month or stated period rather it is known to be terminated with prior notification. This is representational figure at month levels. Use AWS Pricing calculator to try weekly, hourly spike based derivations to go deeper..

Unit conversions
Spot discount: 58/100 = 0.58
Pricing calculations
1 instances x 0.172 USD On Demand hourly cost x 730 hours in a month = 125.560000 USD
125.560000 USD - (125.560000 USD x 0.58) = 52.735200 USD
Spot instances (monthly): 52.735200 USD

Image description

Top comments (0)