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.

Prerequisites

Scenarios

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.

You can adopt the solutions provided in this topic if your application has the following characteristics:
  • 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.

Solutions

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.

You can adopt the following solutions:
  • 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.

Benefits

Auto Scaling enables you to respond to traffic spikes and offers the following benefits:
  • 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.

Procedure

Evaluate business modules based on your business architecture and perform the following operations to implement automatic scaling for specified business modules:

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:

  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 and click Create Instance in the Actions column.
  5. 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:

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

  4. Click View Scaling Group Details.
  5. 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.

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

  1. Go to the ECS Instances page, and add existing subscription ECS instances to the scaling group.
  2. Switch the subscription ECS instances to the Protected state to ensure service availability during daily business.
  3. Go to the Basic Information page, and modify the minimum and maximum numbers of instances in the scaling group based on business needs.
  4. 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.

Result

The state of subscription ECS instances is switched to Protected to ensure service availability during daily business. The ECS instances in the Protected state cannot be removed from the scaling group and their weights in SLB are not affected.

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.