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 respond 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.solution works

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

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

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

  4. Click Details.
  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 a scaling configuration (ECS).

  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 a scaling group and create a target tracking 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 Basic Information tab, change the minimum and maximum numbers of instances in the scaling group based on your business requirements.
  4. 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.

Result

The subscription ECS instances that enter the Protected state are prepared for 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.

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.