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 responds 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 workloads increase, Auto Scaling automatically creates ECS instances, adds the instances to the backend server group of the associated Server Load Balancer (SLB) instance, and adds the private IP addresses of the instances to the whitelist that manages access to the associated ApsaraDB RDS instance. When the workloads decrease, Auto Scaling automatically removes ECS instances from the backend server group of the associated SLB instance and the private 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 instances.
- 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 Instance Configuration Source to Create from Scratch.
- Set Minimum Number of Instances to 0.
- Set Network Type to VPC.
- Set Expansion and Contraction Strategy 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 Manage scaling groups.
- Find the scaling group and click Details in the Actions column.
- 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 the scaling group and create a target tracking scaling 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 Scaling Groups page, find the scaling group and click Edit in the Actions column.
- In the Edit Scaling Group dialog box, change the minimum and maximum numbers of instances that are allowed for the scaling group based on your business requirements.
- Go to the Scaling Rules tab, and create a target tracking scaling 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 Manage scaling rules.
The subscription ECS instances that enter the Protected state are ready to process daily business traffic. The ECS instances that are in the Protected state cannot be removed from the scaling group, and their weights as backend servers of the associated SLB instance are not affected.
Auto Scaling 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 workloads. When the average CPU utilization drops below 50%, Auto Scaling automatically releases ECS instances to reduce costs. The number of ECS instances in the scaling group always ranges from the minimum number of instances allowed for the scaling group to the maximum number of instances allowed for the scaling group. This ensures that business requirements are met and costs are minimized.