# Spot Fleet Strategies: Lowest Price, Diversified, Capacity Optimized

> Chapter 74 of the Courseiva SAA-C03 curriculum — https://courseiva.com/learn/saa-c03/ec2-spot-fleet

**Official objective:** 2.1 — Resilient Architectures

## Introduction

For the SAA-C03 exam’s Resilient Architectures domain, Spot Fleet strategies—lowestPrice, diversified, and capacityOptimized—govern how Amazon EC2 Spot Instances are launched and managed. Understanding these strategies is critical for the SAA-C03 exam, especially in questions about cost optimization and resilient architectures. Approximately 5-10% of exam questions touch on Spot Instances or Spot Fleet, and mastering these strategies can help you eliminate wrong answers quickly. We'll dive into the mechanics, defaults, and exam traps so you can confidently answer any Spot Fleet question.

## Auction House with Three Bidding Strategies

An auction house is where you, the operator, must buy 100 identical antique chairs. You have three bidding strategies. The 'lowestPrice' strategy is like instructing your agent: 'Find me the single cheapest chair from any seller, and buy all 100 from that one seller.' Your agent looks at all sellers, picks the one with the lowest price per chair, and buys the entire lot from them. If that seller runs out of chairs, the agent stops—no further purchases. The 'diversified' strategy is like saying: 'Buy chairs from the 20 cheapest sellers, but allocate purchases proportionally so that cheaper sellers get more of my business.' Your agent sorts sellers by price, then distributes the 100 chairs among the top 20, giving more chairs to cheaper sellers. The 'capacityOptimized' strategy is like saying: 'I don't care about price; I need all 100 chairs right now. Find me the combination of sellers that have the most total chairs available and can deliver the fastest.' Your agent prioritizes sellers with large inventory and quick delivery, even if they are expensive. Each strategy optimizes for a different goal: lowest price per unit, a balanced mix of low price and availability, or maximum total capacity irrespective of cost.

## Core explanation

### What is Spot Fleet and Why Does It Exist?

Spot Fleet is a service that simplifies launching and managing a fleet of Spot Instances. Spot Instances are spare EC2 capacity that AWS offers at up to 90% discount compared to On-Demand, but they can be reclaimed with a 2-minute warning when AWS needs the capacity back. Spot Fleet aggregates multiple Spot Instance requests across instance types and Availability Zones to achieve desired capacity, performance, and cost. The strategies determine how Spot Fleet selects which instance pools (a combination of instance type and Availability Zone) to launch from.

### How Spot Fleet Works Internally

When you create a Spot Fleet, you define a target capacity (number of instances or vCPUs/memory) and a launch specification that includes one or more instance types and subnets (AZs). Spot Fleet then monitors the Spot market and launches instances from the pools that best meet the chosen strategy. The fleet continually evaluates the market and can replace instances that are reclaimed (interrupted) with new ones from different pools, maintaining the target capacity.

### Key Components and Defaults

- **Target capacity**: The total amount of capacity to launch. You can specify in units of instances (count) or in custom units (e.g., vCPUs, memory). Default: no default—required.
- **Allocation strategy**: One of `lowestPrice`, `diversified`, or `capacityOptimized`. Default: `lowestPrice`.
- **Instance pools**: Each unique combination of instance type (e.g., `c5.large`) and Availability Zone (e.g., `us-east-1a`) is a pool. Spot Fleet can launch from up to 20 pools.
- **Maintain target capacity**: If true (default), Spot Fleet automatically replenishes interrupted instances. If false, it launches only once.
- **Spot price**: The maximum price you are willing to pay per instance hour. Excluding this means you pay the current Spot price, which is often lower than On-Demand.
- **Interruption behavior**: What happens when an instance is reclaimed. Options: `stop`, `terminate`, `hibernate`. Default: `terminate`.
- **Instance termination**: By default, Spot Fleet terminates instances when they are interrupted or when you delete the fleet.

### The Three Allocation Strategies in Detail

#### 1. lowestPrice (Default)

This strategy launches instances from the pool that has the lowest Spot price at the time of launch. It is the simplest and most cost-focused. How it works:

- Spot Fleet evaluates all pools in the launch specification.
- It selects the pool with the lowest current Spot price.
- It launches the entire target capacity from that single pool.
- If the pool does not have enough capacity to meet the target, the fleet launches as many as possible and stops. It does NOT fall back to the next cheapest pool.
- If the target capacity is maintained (maintain = true) and instances are interrupted, Spot Fleet again selects the single cheapest pool at that moment and relaunches there.

**Use case**: When you want absolute lowest cost and can tolerate the risk of running in a single AZ/instance type, or if you are running batch jobs that can be interrupted and restarted.

**Risk**: If the cheapest pool becomes unavailable (e.g., price spikes or capacity disappears), the fleet may not be able to maintain capacity. Single-AZ deployment reduces resilience.

#### 2. diversified

This strategy distributes Spot Instance launches across multiple pools. How it works:

- Spot Fleet selects the top N pools by lowest price (N is the number of pools you specify, or defaults to the number of pools in the launch specification).
- It allocates instances across these pools in a way that favors cheaper pools—the cheapest pool gets the most instances, the next cheapest gets fewer, etc.
- The allocation is proportional to the inverse of the Spot price. For example, if pool A is $0.10/hr and pool B is $0.20/hr, pool A gets twice as many instances as pool B.
- If a pool becomes unavailable (e.g., price spikes above your max price or capacity is zero), Spot Fleet redistributes the target capacity among the remaining pools.
- The fleet can also rebalance across pools periodically to maintain the diversification.

**Use case**: When you need high availability and want to avoid putting all eggs in one basket, but still want to optimize cost by preferring cheaper pools. Good for stateless web servers or microservices.

**Risk**: Slightly higher cost than lowestPrice because you may use more expensive pools. But much more resilient.

#### 3. capacityOptimized

This strategy launches instances from the pool that has the most available Spot capacity. How it works:

- Spot Fleet monitors the Spot capacity of each pool (how many instances that pool can currently support without interruption risk).
- It selects the pool with the highest available capacity.
- It launches the entire target capacity from that single pool.
- If that pool runs out of capacity, it selects the next highest capacity pool and launches there.
- This strategy does NOT consider price at all.

**Use case**: When you need to launch a large number of instances quickly and cannot tolerate interruptions, such as for urgent data processing, rendering, or large-scale simulations.

**Risk**: Higher cost because you may use expensive pools. But maximizes the chance of getting and keeping capacity.

### How Spot Fleet Interacts with Related Technologies

- **Auto Scaling Groups (ASGs)**: You can use a mixed instances policy within an ASG to combine On-Demand and Spot Instances, with Spot allocation strategies. However, Spot Fleet is a standalone service; ASG uses a different mechanism.
- **EC2 Fleet**: EC2 Fleet is similar to Spot Fleet but can also launch On-Demand and Reserved Instances. Spot Fleet only launches Spot Instances.
- **Spot Instance Interruptions**: All strategies are affected by interruptions. With `maintain = true`, Spot Fleet automatically relaunches interrupted instances using the same strategy.
- **Instance Weighting**: You can define weights for each instance type (e.g., vCPUs) to meet target capacity in units other than instance count.

### Configuration Example

To create a Spot Fleet with the diversified strategy using the AWS CLI:

```bash
aws ec2 request-spot-fleet \
    --spot-fleet-request-config file://config.json
```

Example `config.json`:
```json
{
    "TargetCapacity": 100,
    "AllocationStrategy": "diversified",
    "SpotPrice": "0.50",
    "IamFleetRole": "arn:aws:iam::123456789012:role/aws-ec2-spot-fleet-tagging-role",
    "LaunchSpecifications": [
        {
            "InstanceType": "c5.large",
            "ImageId": "ami-0abcdef1234567890",
            "SubnetId": "subnet-0a1b2c3d4e5f67890"
        },
        {
            "InstanceType": "m5.large",
            "ImageId": "ami-0abcdef1234567890",
            "SubnetId": "subnet-0a1b2c3d4e5f67891"
        }
    ],
    "TerminateInstancesWithExpiration": true
}
```

To verify the fleet:
```bash
aws ec2 describe-spot-fleet-requests
aws ec2 describe-spot-fleet-instances --spot-fleet-request-id sfr-1234567890abcdef0
```

### Important Defaults and Limits

- Default allocation strategy: `lowestPrice`
- Maximum number of instance pools: 20
- Target capacity can be up to 10,000 units
- Spot Fleet does not support Cross-zone load balancing (unlike ASGs)
- You cannot modify the allocation strategy after the fleet is created; you must create a new fleet.

### Exam-First Summary

The exam tests your ability to choose the right strategy based on requirements:
- **Cost optimization with tolerance for single-AZ failure?** → `lowestPrice`
- **High availability and cost savings?** → `diversified`
- **Large capacity quickly, cost is secondary?** → `capacityOptimized`

Remember: `lowestPrice` uses ONE pool, `diversified` uses MULTIPLE pools, `capacityOptimized` uses ONE pool but picks the one with most capacity.

## Real-world context

### Enterprise Scenario 1: Large-Scale Batch Processing

A pharmaceutical company runs drug discovery simulations that require 10,000 vCPUs for 8 hours every night. The workload is fault-tolerant: if some instances are interrupted, the simulation can restart on new instances. The company uses Spot Fleet with the `lowestPrice` strategy to minimize costs. They specify multiple instance types (c5.4xlarge, c5a.4xlarge, m5.4xlarge) across three Availability Zones. Each night, the fleet launches from the cheapest pool. If that pool's price spikes, the fleet may fail to launch all capacity, but the company accepts this risk. They set `maintain = false` because the job is ephemeral. A common misconfiguration is using `capacityOptimized` here, which would increase costs unnecessarily.

### Enterprise Scenario 2: Stateless Web Application

A SaaS company runs a stateless web application on Spot Instances behind an Application Load Balancer. They need high availability and cannot tolerate all instances being interrupted at once. They use Spot Fleet with the `diversified` strategy across multiple instance types (t3.medium, t3a.medium, m5.large) and three AZs. The fleet distributes instances across the cheapest pools, ensuring that no single AZ or instance type carries all traffic. If one pool becomes unavailable, traffic shifts to the remaining pools. The company sets `maintain = true` to automatically replace interrupted instances. A common mistake is using `lowestPrice`, which would put all instances in one AZ, creating a single point of failure.

### Enterprise Scenario 3: Urgent Rendering for Media

A media company needs to render 50,000 frames for a movie premiere in 2 hours. Cost is secondary; they need maximum compute capacity immediately. They use Spot Fleet with the `capacityOptimized` strategy, selecting multiple GPU instance types (p3.2xlarge, p3.8xlarge, g4dn.xlarge) across all AZs. The fleet picks the pool with the most available Spot capacity, launching all 50,000 instances as fast as possible. If a pool runs out, it moves to the next. The company sets `maintain = true` to ensure any interrupted frames are re-rendered. A misconfiguration would be using `lowestPrice`, which could delay the launch if the cheapest pool has limited capacity.

### Performance Considerations

- **Launch speed**: capacityOptimized launches fastest because it targets pools with ample capacity. diversified can be slower due to coordination across pools. lowestPrice may be fast if the cheapest pool has capacity, but may be slow or fail if not.
- **Cost**: lowestPrice yields lowest cost, diversified is moderate, capacityOptimized is highest.
- **Interruption rate**: capacityOptimized minimizes interruptions because it uses pools with more available capacity. diversified reduces impact of interruptions but does not avoid them. lowestPrice may experience more interruptions if the cheapest pool is volatile.

### What Goes Wrong When Misconfigured

- Using `lowestPrice` for a high-availability workload: all instances launch in one AZ. If that AZ fails or the Spot price spikes, the entire fleet is lost. The application goes down.
- Using `capacityOptimized` for a cost-sensitive batch job: you pay more than necessary, potentially exceeding budget.
- Forgetting to set `maintain = true` for a long-running workload: interrupted instances are not replaced, causing capacity to dwindle over time.
- Specifying too few instance types or AZs: limits pool diversity, increasing risk of capacity shortages.

## Exam focus

### What SAA-C03 Tests on Spot Fleet Strategies (Objective 2.1)

The exam tests your ability to select the correct allocation strategy based on requirements for cost, availability, and capacity. Specific objectives include:
- 2.1: Design resilient architectures with Spot Instances.
- 2.2: Implement cost-optimized architectures.
- 3.1: Select appropriate compute options.

### Common Wrong Answers and Why Candidates Choose Them

1. **Choosing `lowestPrice` for high availability**: Candidates assume cheapest is always best, but `lowestPrice` puts all instances in one pool, creating a single point of failure. The correct answer is `diversified` when high availability is required.
2. **Choosing `diversified` for urgent capacity**: Candidates think diversification is always good, but `diversified` may not launch fast enough because it spreads across multiple pools. `capacityOptimized` is faster.
3. **Thinking `capacityOptimized` is the cheapest**: It is actually the most expensive because it ignores price. Candidates confuse 'optimized' with 'cost-optimized'.
4. **Assuming you can change strategy after creation**: You cannot. Candidates may propose modifying the fleet instead of creating a new one.

### Specific Numbers and Terms That Appear on the Exam

- The default allocation strategy is `lowestPrice`.
- Maximum number of instance pools: 20.
- Target capacity can be in instances or custom units (vCPUs, memory).
- `maintain` defaults to true.
- Spot Fleet does not support On-Demand instances; use EC2 Fleet for mixed.

### Edge Cases and Exceptions

- If you specify a `SpotPrice` (max price) and the cheapest pool's price exceeds it, the fleet will not launch from that pool. For `diversified`, it will skip pools above your max price.
- If all pools exceed your max price, the fleet fails to launch any instances.
- For `diversified`, you can specify the number of pools to use via `InstancePoolsToUseCount`. Default is the number of pools in the launch specification (up to 20).
- `capacityOptimized` does not support a max price; it ignores the `SpotPrice` parameter.

### How to Eliminate Wrong Answers

- If the question mentions 'high availability' or 'fault tolerance', eliminate `lowestPrice` and `capacityOptimized`.
- If the question mentions 'fastest launch' or 'urgent', eliminate `lowestPrice` and `diversified`.
- If the question mentions 'lowest cost' without availability concerns, eliminate `diversified` and `capacityOptimized`.
- If the question mentions 'moderate cost and high availability', choose `diversified`.

## Step by step

1. **Define Target Capacity** — First, you specify the total amount of capacity you need, either as a number of instances (e.g., 100) or in custom units (e.g., 512 vCPUs). This is the target that Spot Fleet will attempt to launch and maintain. If you use custom units, you must assign a weight to each instance type in the launch specification. The default unit is instance count. This step is mandatory; without a target capacity, the fleet request fails.
2. **Select Allocation Strategy** — You choose one of three strategies: lowestPrice, diversified, or capacityOptimized. This decision determines how Spot Fleet selects which instance pools to launch from. The default is lowestPrice. The strategy cannot be changed after the fleet is created. If you choose diversified, you can optionally specify the number of pools to distribute across (default: all pools in the launch specification). For capacityOptimized, the fleet monitors real-time capacity availability.
3. **Specify Launch Specifications** — You define one or more launch specifications, each containing an Amazon Machine Image (AMI), instance type, subnet (AZ), security groups, key pair, and optional user data. Each unique combination of instance type and subnet constitutes a pool. You can specify up to 20 pools. The fleet will only launch instances from these pools. If you omit a subnet, the fleet uses the default VPC and default subnet.
4. **Fleet Launches Instances** — Based on the allocation strategy, Spot Fleet evaluates the current Spot market and launches instances from the selected pool(s). For lowestPrice, it picks the single cheapest pool. For diversified, it allocates across the top N cheapest pools proportionally. For capacityOptimized, it picks the pool with the most available capacity. The fleet launches instances up to the target capacity. If a pool lacks sufficient capacity, the fleet may partially launch and stop (lowestPrice) or redistribute (diversified).
5. **Maintain Capacity (Optional)** — If you set `maintain` to true (default), Spot Fleet continuously monitors the target capacity. When an instance is interrupted (due to Spot price changes or capacity reclaim), the fleet automatically launches a replacement instance from the best available pool according to the same allocation strategy. If `maintain` is false, the fleet launches once and does not replace interrupted instances. This is useful for one-time batch jobs.

## Comparisons

### lowestPrice vs diversified

**lowestPrice:**
- Launches from single cheapest pool
- Lowest possible cost
- High risk of single-AZ failure
- No automatic fallback if pool lacks capacity
- Best for fault-tolerant, cost-sensitive batch jobs

**diversified:**
- Distributes across multiple cheapest pools
- Moderate cost (may use some expensive pools)
- High availability across pools
- Automatically redistributes if a pool fails
- Best for stateless applications needing reliability

### diversified vs capacityOptimized

**diversified:**
- Optimizes for cost while maintaining availability
- Launches from multiple pools
- Slower launch due to coordination
- Considers price in allocation
- Good for long-running services

**capacityOptimized:**
- Optimizes for capacity availability only
- Launches from single pool with most capacity
- Fastest launch possible
- Ignores price entirely
- Best for urgent, large-scale workloads

## Common misconceptions

- **Misconception:** Spot Fleet with lowestPrice automatically fails over to the next cheapest pool if the cheapest pool has no capacity. **Reality:** No. With lowestPrice, if the cheapest pool cannot fulfill the entire target capacity, the fleet launches as many as possible and stops. It does not fall back to other pools. This is a common exam trap.
- **Misconception:** Diversified strategy distributes instances equally across all pools. **Reality:** No. Diversified allocates proportionally to the inverse of price—cheaper pools get more instances. It is not an equal distribution.
- **Misconception:** CapacityOptimized strategy considers the Spot price when selecting a pool. **Reality:** No. CapacityOptimized completely ignores price. It only looks at available capacity. This can lead to higher costs.
- **Misconception:** You can change the allocation strategy of an existing Spot Fleet. **Reality:** No. The allocation strategy is set at creation and cannot be modified. You must delete and recreate the fleet.
- **Misconception:** Spot Fleet can launch On-Demand instances if Spot capacity is unavailable. **Reality:** No. Spot Fleet launches only Spot Instances. To mix On-Demand and Spot, use EC2 Fleet or an Auto Scaling Group with a mixed instances policy.

## Key takeaways

- Spot Fleet allocation strategies: lowestPrice (default), diversified, capacityOptimized.
- lowestPrice uses one pool; diversified uses multiple pools proportionally; capacityOptimized uses one pool with most capacity.
- You cannot change the allocation strategy after fleet creation.
- For high availability, use diversified; for lowest cost, use lowestPrice; for fastest launch, use capacityOptimized.
- Spot Fleet only launches Spot Instances; use EC2 Fleet for On-Demand + Spot mix.
- Maximum of 20 instance pools in a Spot Fleet.
- maintain parameter defaults to true, automatically replacing interrupted instances.
- capacityOptimized ignores the SpotPrice parameter.
- If lowestPrice pool lacks capacity, the fleet does not fall back to other pools.
- Diversified allocation is proportional to inverse of price, not equal.

## FAQ

**What is the default allocation strategy for Spot Fleet?**

The default allocation strategy is lowestPrice. If you do not specify a strategy when creating a Spot Fleet, AWS will use lowestPrice. This is important for the exam because they may ask about the default behavior.

**Can I use Spot Fleet to launch both On-Demand and Spot Instances?**

No. Spot Fleet only launches Spot Instances. To launch a mix of On-Demand and Spot Instances, you should use EC2 Fleet or an Auto Scaling Group with a mixed instances policy. This is a common exam distinction.

**Does diversified strategy distribute instances equally across pools?**

No. Diversified distributes instances proportionally based on the inverse of the Spot price. Cheaper pools receive more instances than expensive ones. It is not an equal distribution.

**What happens if the cheapest pool in lowestPrice cannot meet the target capacity?**

Spot Fleet will launch as many instances as possible from that pool and then stop. It does not automatically fall back to the next cheapest pool. This is a key exam point.

**When should I use capacityOptimized?**

Use capacityOptimized when you need to launch a large number of instances quickly and cost is not the primary concern. It selects the pool with the most available Spot capacity, minimizing the risk of interruptions and maximizing launch speed.

**Can I modify the allocation strategy after creating a Spot Fleet?**

No. The allocation strategy is set at creation and cannot be changed. You must delete the existing fleet and create a new one with the desired strategy.

**What is the maximum number of instance pools I can specify in a Spot Fleet?**

The maximum is 20 instance pools. Each pool is a unique combination of instance type and Availability Zone.

---

Interactive version with quiz and diagrams: https://courseiva.com/learn/saa-c03/ec2-spot-fleet
