After you create a scaling group, you can set appropriate scaling policies to improve resource utilization and reduce costs. To further lower your costs, you can add spot instances to use ECS instances at a lower price. This topic shows you how to use spot instances to reduce your cluster costs.
Only scaling groups for ECS instances support spot instances.
What is a spot instance?
A spot instance is a type of on-demand instance that offers the same performance as a regular ECS instance. Its price changes in real time based on market supply and demand, saving you up to 90% compared to a pay-as-you-go instance. Spot instances have the following characteristics:
Identical performance: For the same instance type, a spot instance performs identically to a pay-as-you-go instance. Only the billing method is different.
Bidding mechanism: You can set a bid price when you create a spot instance. Alibaba Cloud adjusts the market price based on current supply and demand. If the market price exceeds your bid, the instance is reclaimed. You can also use Automatic Bidding, which automatically follows the market price up to the price of a pay-as-you-go instance.
Price matching mechanism: The price of an instance changes in real time based on market supply and demand. Your bid is compared with the market price. If your bid is higher than the market price and inventory is sufficient, a spot instance is created.
Interruption and reclamation mechanism: Spot instances are subject to an interruption and reclamation mechanism. If the market price exceeds your bid or if inventory is insufficient, the instance is interrupted and reclaimed.
Protection period: You can set a 1-hour protection period to prevent the instance from being reclaimed within the first hour after its creation.
For more information about spot instances, see What is a spot instance?.
Summary: When using a scaling group, you can use lower-priced spot instances to reduce costs. However, this comes at the cost of stability, as there is no guarantee that instances will be successfully created or will run indefinitely.
Balance cost and stability with spot instances
Using lower-priced spot instances can effectively reduce the cost of your instance cluster in a scaling group. However, due to their inherent instability, you need to carefully assess the potential impact on your cluster's overall stability. A scaling group's stability has two key aspects:
Scale-out stability: The ability to launch new instances in a timely and reliable manner to meet scaling demands when the workload increases.
When you use spot instances, their creation might fail due to market price fluctuations or insufficient inventory. This can affect scale-out stability, but you can configure several mechanisms to improve it.
Instance stability: The ability to ensure that running instances operate continuously without unexpected interruptions.
Introducing spot instances means some instances might be automatically reclaimed due to market price fluctuations or insufficient inventory. This requires your application to recover quickly and seamlessly switch to other available resources after an instance is interrupted.
Finding the right balance between cost savings and cluster stability is crucial for maintaining service reliability and performance.
Balancing cost and stability
Use the following strategies to balance cost and cluster stability.
Set a reasonable bidding strategy: By setting a bid slightly higher than the market price but lower than the pay-as-you-go price, you can increase your chances of acquiring spot instances while reducing the management overhead caused by frequent interruptions.
Use a mix of instance types: When adding spot instances to a scaling group, you must adjust the ratio of spot instances to pay-as-you-go instances based on your business needs to balance cost and cluster stability.
For example, you can set the proportion of pay-as-you-go instances to the minimum capacity required to ensure stable operation and use spot instances for the elastic portion to reduce costs.
The following figure shows how cluster stability and cost change with different instance ratios. As the proportion of spot instances in the cluster increases, costs decrease, but stability also decreases.

Improve cluster stability
In addition to designing a balanced strategy, you can use the following configurations to further enhance cluster stability.
| |
| |
| |
| |
|
Example: Add spot instances to a scaling group
Follow these steps to add spot instances to an existing scaling group.
Step 1: Configure vSwitches in multiple zones
Configuring vSwitches across multiple zones combines their inventory, increasing the available spot instances for the scaling group.
|
|
|
|
|
|
Step 2: Configure a cost optimization policy
|
|
|
|
|
Step 3: Modify the scaling configuration
This section shows how to modify an existing scaling configuration. You can also create a new one. For details, see Create an ECS scaling group.
|
|
|
|
| |
|
|
|
This example uses Automatic Bidding. |
|
Step 4: Verify the scale-out
After completing the configuration, trigger a scale-out activity to verify that the scaling group creates spot instances as expected. This example triggers a scale-out by modifying the expected number of instances.
Parameters
Percentage of Pay-as-you-go Instances: 70%.
Minimum Number of Pay-as-you-go Instances: 2
Expected Number of Instances: Changed from 0 to 12.
Expected result
9 pay-as-you-go instances and 3 spot instances.
Result calculation
After the Minimum Number of Pay-as-you-go Instances is met, the Percentage of Pay-as-you-go Instances is applied to any additional instances. Therefore, the total number of pay-as-you-go instances is
You can view the billing method of an instance in the ECS console.








