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.

Prerequisites

Business scenario

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.

If your application has the following characteristics, you can use the solution that is described in this topic:
  • 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.

Solution

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.

This solution involves the following operations:
  • 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.
The following figure shows how the solution works.image

Benefits

Auto Scaling helps you handle traffic spikes and provides the following benefits:
  • 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.

Procedure

Evaluate business modules based on your business architecture and perform the following operations to apply automatic scaling to specific business modules:

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:

  1. Log on to the ECS console.
  2. In the left-side navigation pane, choose Instances & Images > Images.
  3. In the top navigation bar, select a region.
  4. Find the custom image of the web application that you want to manage and click Create Instance in the Actions column.
  5. 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:

  1. Log on to the Auto Scaling console.
  2. In the top navigation bar, select the region where Auto Scaling is activated.
  3. 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.

  4. Find the scaling group and click Details in the Actions column.
  5. In the upper part of the page, click the Instance Configuration Sources tab.
  6. 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 scaling configurations for scaling groups that contain ECS instances.

  7. 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:

  1. On the Instances tab, add the existing subscription ECS instances to the scaling group.
  2. Put the subscription ECS instances into the Protected state to ensure service availability.
  3. On the Scaling Groups page, find the scaling group and click Edit in the Actions column.
  4. 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.
  5. 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.

Result

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.