This topic describes how to use Auto Scaling to build a scalable web application that can automatically respond to changes in demand. This allows you to cope with the sudden increase in traffic during major activities while handling your daily business in a stable manner.
An e-commerce platform launches promotions during holidays, membership days, and shopping festivals to attract users. To handle traffic spikes during promotions, O&M personnel can estimate the required computing resources for upcoming promotional events based on historical data. However, if actual traffic volumes during peak hours are beyond expectations, O&M personnel must manually create Elastic Compute Service (ECS) instances. This is time-consuming and may interrupt your business.
- Deployed in a cluster that has at least one server.
- Has traffic spikes for a short period of time. For example, the traffic spikes last no more than 9 hours each day and no more than 20 days each month.
Auto Scaling automatically scales computing resources based on the change in your workloads without the need for estimation and manual intervention. This ensures the availability of your application. During big promotions such as Double 11, Auto Scaling can deliver up to thousands of ECS instances within minutes and automatically respond to traffic spikes at the earliest opportunity to ensure service availability.
- Purchase subscription ECS instances to meet daily business requirements.
- Use Auto Scaling to monitor workload changes and automatically create ECS instances to handle unexpected traffic spikes.
- Zero backup resource costs
Auto Scaling automatically creates and releases ECS instances based on your business requirements. You do not need to prepare backup resources. You only need to reserve computing resources for daily business traffic.
- Zero O&M costs
You can configure scaling policies in advance. When the load increases, Auto Scaling automatically creates ECS instances and adds the instances to the backend server group of the associated Server Load Balancer (SLB) instance and IP addresses of the instances to the whitelist that manages access to the associated ApsaraDB RDS instance. When the load decreases, Auto Scaling automatically removes ECS instances from the backend server group of the associated SLB instance and IP addresses from the whitelist that manages access to the associated ApsaraDB RDS instance and then releases the instances. The whole process is automatically triggered and completed without manual intervention.
- Flexibility and intelligence
Auto Scaling provides various scaling modes. You can combine multiple scaling modes based on the changes in your business to obtain the solution that best suits your business. For example, if your web application usually receives a steady volume of traffic but occasionally experiences a sudden spike in traffic, you can use the dynamic mode based on CloudMonitor metrics to monitor the average CPU utilization and the system can automatically respond to traffic changes at the earliest opportunity.
Step 1: Use a custom image to create subscription ECS instances
Create a specified number of subscription ECS instances and add the instances to the scaling group based on the 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 that you want to manage and click Create Instance in the Actions column.
- Configure the required 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 business requirements. For more information, see Create an instance by using the 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 Scaling Policy to Balanced Distribution Policy.
- Set Instance Reclaim Mode to Release.
- Associate the SLB and ApsaraDB RDS instances required by your current business modules with the scaling group.
Configure other parameters based on your business requirements. For more information, see Create a scaling group.
- Click Details.
- In the upper part of the page, click the Instance Configuration Sources tab.
- Create a scaling configuration. Set Image to the custom image of the web application.
Configure other parameters based on your business requirements. For more information, see Create a scaling configuration (ECS).
- 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 automatically scale instances. Perform the following operations:
- On the Instances tab, add the existing subscription ECS instances to the scaling group.
- Put the subscription ECS instances into the Protected state to ensure service availability.
- On the Basic Information tab, change the minimum and maximum numbers of instances in the scaling group based on your business requirements.
- Go to the Scaling Rules tab, and create a target tracking rule.
- Set Rule Type to Target Tracking Scaling Rule.
- Set Metric Type to (ECS) Average CPU Utilization.
- Set Target Value to 50%.
Configure other parameters based on your business requirements. For more information, see Create a scaling rule.
The scaling group automatically maintains the average CPU utilization of ECS instances at approximately 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 minimum number of instances and less than or equal to the maximum number of instances to meet business requirements and maintain costs within the expected range.