This topic describes how to build a scalable web application by using Auto Scaling that can automatically respond to increases and decreases in business activities. This allows you to handle daily business and traffic spikes during major activities.
- Before you perform the operations provided in the tutorial, you must have registered an Alibaba Cloud account. To create an Alibaba Cloud account, click Create a new Alibaba Cloud account.
- A custom image is created for an ECS instance. For more information, see Create a custom image by using an instance.
An e-commerce platform launches promotions during holidays, member days, and shopping festivals to attract users. To handle the traffic spikes during promotions, the operations and maintenance (O&M) personnel estimate the compute resources required for new promotional activities based on historical data. If unexpected traffic spikes occur during peak hours, the O&M personnel must manually create ECS instances. This is time-consuming and may affect the availability of your application.
- Deployed in a cluster that has at least one server.
- Has traffic spikes for a short duration. For example, the traffic spikes last no more than nine hours each day, and no more than 20 days each month.
Auto Scaling automatically scales compute resources based on increases and decreases in business activities without the need for prediction and manual intervention. This ensures the availability of your application. Especially during big promotions such as Double 11, Auto Scaling can deliver up to thousands of ECS instances within minutes, and respond to traffic spikes automatically and timely to ensure service availability.
- Purchase subscription ECS instances to meet daily business requirements.
- Use Auto Scaling to monitor load changes and automatically create ECS instances in response to unexpected traffic spikes.
- Zero backup resource cost
Auto Scaling automatically creates and releases ECS instances based on your requirements. You do not need to maintain backup resources. You only need to reserve compute resources for daily business traffic.
- Zero maintenance cost
You can configure the scaling policy in advance. When the load increases, Auto Scaling automatically creates and adds ECS instances to the whitelist of the ApsaraDB for RDS instance and SLB backend server group. When the load decreases, Auto Scaling automatically removes ECS instances from the SLB backend server group and the whitelist of the ApsaraDB for RDS instance, and then releases the instances. The whole process is automatically triggered and completed without the need for manual intervention.
- Flexibility and intelligence
Auto Scaling provides a variety of scaling modes. You can select a combination of multiple scaling modes based on business changes to implement the optimal match for your business. For example, if your web application that requires a large and steady volume of traffic experiences a temporary traffic spike, you can use the dynamic mode based on CloudMonitor metrics. This allows you to monitor average CPU utilization and automatically respond to traffic changes in a timely manner.
Step 1: Use a custom image to create subscription ECS instances
Create and add the specified number of subscription ECS instances to a scaling group in response to daily traffic requirements of business modules. Perform the following operations:
- Log on to the ECS console.
- In the left-side navigation pane, choose .
- In the top navigation bar, select a region.
- Find the custom image of the web application and click Create Instance in the Actions column.
- Configure the parameters to create the instance.
- Set Billing Method to Subscription.
- Information in the Region and Image sections is automatically filled.
Configure other parameters based on your needs. For more information, see Create an instance by using the provided wizard.
Step 2: Create and enable a scaling group
Create a scaling group for business modules that require elastic scaling. Select a custom image for the scaling configuration to ensure that automatically created ECS instances meet web application requirements. Perform the following operations:
- Log on to the Auto Scaling console.
- In the top navigation bar, select a region.
- Create a scaling group:
- Set Source Type to Create from Scratch.
- Set Minimum Number of Instances to 0.
- Set Network Type to VPC.
- Set Multi-zone Scaling Policy to Balanced Distribution Policy.
- Set Instance Reclaim Mode to Release Mode.
- Bind the SLB and ApsaraDB for RDS instances used by your current business modules.
Configure other parameters based on your needs. For more information, see Create a scaling group.
- Click View Scaling Group Details.
- Go to the Instance Configuration Source page to create a scaling configuration.
Set Image to the custom image of the web application.
Configure other parameters based on your needs. For more information, see Create a scaling configuration.
- Enable the scaling configuration and scaling group.
Step 3: Add subscription ECS instances and configure the automatic scaling policy
Add subscription ECS instances to a scaling group and create a target tracking rule to implement automatic scaling based on traffic changes in response to traffic spikes. Perform the following operations:
- Go to the ECS Instances page, and add existing subscription ECS instances to the scaling group.
- Switch the subscription ECS instances to the Protected state to ensure service availability during daily business.
- Go to the Basic Information page, and modify the minimum and maximum numbers of instances in the scaling group based on business needs.
- Go to the Scaling Rules page, and create a target tracking rule.
- Set Rule Type to Target Tracking Scaling Rule.
- Set Metric Name to Average CPU Usage.
- Set Target Value to 50%.
Configure other parameters based on your needs. For more information, see Create a scaling rule.
The scaling group automatically keeps the average CPU utilization of ECS instances at about 50%. When the average CPU utilization exceeds 50%, Auto Scaling automatically creates ECS instances to balance loads. When the average CPU utilization drops below 50%, Auto Scaling automatically releases ECS instances to reduce costs. The number of ECS instances remains greater than or equal to the specified minimum number of instances, and less than or equal to the maximum number of instances to meet business requirements and keep costs within expectation.