All Products
Search
Document Center

Auto Scaling:Use lifecycle hooks to ensure service availability

Last Updated:Jul 18, 2026

After you associate a scaling group with a Classic Load Balancer (CLB), Application Load Balancer (ALB), or Network Load Balancer (NLB), instances in the scaling group are automatically added to the backend server group to serve client requests. You can use lifecycle hooks to pause this process, giving you time to perform custom actions and ensure high availability.

Key concepts

The following table describes key concepts used in this topic.

Parameter

Description

References

load balancer

A load balancer distributes incoming traffic across multiple backend servers to increase throughput, eliminate single points of failure, and improve availability.

Alibaba Cloud Server Load Balancer (SLB) offers three types of load balancers: Classic Load Balancer (CLB), Application Load Balancer (ALB), and Network Load Balancer (NLB).

Introduction to the Server Load Balancer (SLB) family

lifecycle hook

A lifecycle hook lets you manage the lifecycle of ECS or ECI instances within a scaling group.

Lifecycle hook overview

Procedure

The following examples use a scaling group associated with a CLB instance to show how lifecycle hooks affect application services during scale-out and scale-in events.

Note

Before you begin, make sure that your scaling group is associated with a CLB instance, or with an ALB or NLB backend server group. For more information, see Add and remove load balancers for a scaling group.

Scenario 1: Scale-out

Impact comparison

The following table compares application behavior during a scale-out event with and without a lifecycle hook.

Condition

Description

Without a lifecycle hook

During a scale-out event, new ECS or ECI instances are added directly to the scaling group. This includes adding them to the backend server group of the associated CLB instance, and they immediately start serving traffic. However, the application on the instance needs time to start. If the application receives requests before it is ready, the requests fail.

With a lifecycle hook

During a scale-out event, before an ECS or ECI instance is added to the backend server group of the CLB instance, a lifecycle hook pauses the new instance. This pause allows the application to fully start. After the lifecycle hook's timeout period ends, the instance is automatically added to the backend server group to serve traffic.

Procedure and considerations

To use a lifecycle hook, you must first create one. For more information, see Create a lifecycle hook.

When you create a lifecycle hook, configure the following parameters:

  • Set Scaling Activity to Scale-out Event.

  • We recommend that you set the Timeout Period to the time required for the application in an ECS or ECI instance to start up normally. The value must be an integer in seconds, and the allowed range is 30 ≤ Timeout Period ≤ 21600.

    Note

    To end the timeout period early, you can call the CompleteLifecycleAction API operation.

  • Set Default Execution Policy to Continue.

After the lifecycle hook is created, new instances from a scale-out event first enter the Pending Add state and wait for the timeout period to expire. During this pending state, the application on the instance can complete its startup process. After the pending state ends, the instance is added to the scaling group and is registered with the CLB instance's backend server group. The instance then transitions to the In Service state and begins to serve traffic, which ensures service availability.

Scenario 2: Scale-in

Impact comparison

The following table compares application behavior during a scale-in event with and without a lifecycle hook.

Condition

Description

Without a lifecycle hook

During a scale-in event, instances selected for termination are immediately removed from the scaling group. This includes removing them from the backend server group of the associated CLB instance, which causes them to stop serving traffic. If the instance has unprocessed client requests, these requests are dropped, resulting in client-side errors.

With a lifecycle hook

During a scale-in event, after an ECS or ECI instance is removed from the backend server group of the associated CLB instance, a lifecycle hook pauses the instance. This allows the instance to finish processing any in-flight requests. After the timeout period for the lifecycle hook ends, the instance is removed from the scaling group. This process prevents client-side interruptions.

Procedure and considerations

Create a lifecycle hook for your scaling group to handle scale-in events gracefully. For more information, see Create a lifecycle hook.

When you create a lifecycle hook, configure the following parameters:

  • Set Scaling Activity to Scale-in Event.

  • We recommend that you set the Timeout Period to the longest processing time for all requests. The value is measured in seconds and must be an integer, and 30 ≤ Timeout Period ≤ 21,600.

    Note

    To end the timeout period early, you can call the CompleteLifecycleAction API operation. For more information, see CompleteLifecycleAction.

After the lifecycle hook is created, instances selected for termination are first removed from the backend server group of the associated CLB instance. They then enter the Pending Remove state and wait for the timeout period to expire. During this pending state, the instances finish processing any in-flight requests but do not accept new ones. After the pending state ends, the instances are removed from the scaling group. This process ensures service availability.