Thursday, April 24, 2025

A clear breakdown of AWS Spot Requests vs Spot Instances, & how they work together.

 

A clear breakdown of AWS Spot Requests vs Spot Instances, and how they work together:

 What Are Spot Instances?

  • Spot Instances are unused EC2 capacity offered at a discount (up to 90% cheaper than On-Demand).
  • They can be terminated by AWS at any time if the capacity is needed back or your max bid is exceeded.
  • Great for fault-tolerant or flexible workloads (e.g., batch jobs, CI/CD, big data, stateless microservices).

 What Is a Spot Request?

A Spot Request is how you ask AWS to give you a Spot Instance.

There are two types:

Type

Description

One-time

AWS launches the Spot Instance once. After it runs (or is terminated), it’s done.

Persistent

AWS will keep trying to launch a new instance if the existing one is terminated (e.g., due to capacity issues or manual termination).

 Relationship Between the Two

  • You submit a Spot Request, and if capacity and price allow, a Spot Instance is launched.
  • If you terminate the instance but leave the request active (persistent), AWS may launch another.
  • To prevent that, you need to cancel the request before terminating the instance.

 Lifecycle Flow (Typical)

  1. You submit a Spot Request via Console, CLI, SDK, or IaC (like Terraform).
  2. AWS evaluates if there’s capacity and if your max price is acceptable.
  3. If yes, AWS launches a Spot Instance.
  4. If the request is persistent, AWS will monitor and attempt re-launches if needed.

In AWS, Spot Instances are tied to Spot Requests — and here's why the request must be canceled before terminating the instance:

 Spot Request Auto-Replacement

When you launch a Spot Instance via a persistent spot request, AWS assumes you want that instance type at that price continuously. So if you just terminate the instance without canceling the request:

  • AWS will automatically launch a replacement instance (because the request is still active).
  • That means your cost continues, and you might lose control over what's running.

 Canceling the Spot Request First

When you cancel the spot request first, you tell AWS:

  • "I don't want this anymore — stop trying to fulfill this request."
  • Then when you terminate the instance, AWS won't try to replace it.

 One-time vs. Persistent Spot Requests

  • Persistent spot request: Keeps trying to fulfill the request even after termination.
  • One-time spot request: If fulfilled and the instance is terminated, AWS won't try to replace it. But still best practice to cancel it for clarity and cost control. 

twtech Best Practice:

  1. First, cancel the spot request.
  2. Second, terminate the instance.
  3. Always cancel persistent requests before terminating instances to avoid auto-replacement.
  4.  Clean up old or failed spot requests to avoid confusion and extra billing.
  5.  Use Auto Scaling Groups with Mixed Instances or EC2 Fleet for more control and resiliency.

No comments:

Post a Comment

Kubernetes Clusters | Upstream Vs Downstream.

  The terms "upstream" and "downstream" in the context of Kubernetes clusters often refer to the direction of code fl...