All Products
Search
Document Center

Auto Scaling:Evolve a web service to an elastic and highly available architecture

Last Updated:Aug 18, 2026

As your business grows, the load on your monolithic web service increases, which can reduce system stability. To address this, you can evolve your monolithic architecture into an elastic and highly available one by using a scaling group to scale out servers and distribute the load. This approach improves system stability and response speed.

Why use an elastic and highly available architecture?

Problems with a monolithic architecture

In a typical monolithic architecture, all resources are deployed on a single ECS instance. Users access the service on this single server directly through a domain name or IP address. This architecture has two main problems:

  • Single point of failure: If the service fails, the entire business is interrupted. This severely impacts user experience and can lead to customer loss.

  • Performance bottlenecks: As traffic grows, a monolithic architecture can hit performance limits, hindering business expansion. Sudden traffic spikes can easily slow down service response times.

image

Features of a highly available architecture

In an elastic and highly available architecture, a load balancer routes user requests to business services running on instances in the cluster. This architecture has the following key features:

  • No single point of failure (high availability): It uses multiple servers to distribute the load, increasing service capacity and preventing interruptions from single-server failures.

  • Elastic scaling: You can use a scaling group to manage the service cluster and change the number of servers with a single click for rapid scaling out. You can also set up automatic scaling policies to scale resources based on application load.

image

How to evolve to a highly available architecture

image

As shown in the figure, evolving from the monolithic architecture on the left to an elastic and highly available architecture involves two phases.

  • Phase 1: Separate data storage from business logic

    An elastic and highly available architecture replicates entire ECS instances. Therefore, you must separate the data storage and business logic of your ECS instances (and the services within them). This is also known as making them stateless, and it prevents data consistency issues when you scale out by adding more instances.

    For example, when replicating an ECS instance, you should ensure that the database is not copied, thereby preventing the cluster from using multiple different data sources. By separating data storage from the ECS instance, you ensure all instances share the same data source, maintaining data consistency.

    If you encounter any of the following common situations, you need to assess the potential impact on your business and adjust your architecture accordingly.

    Common situations to watch for

    Situation 1: Stateful services on the instance

    If your ECS instance contains stateful services like a database, replicating this instance to scale out will result in multiple data sources in your cluster, leading to data inconsistency. Separate stateful services like MySQL or Redis into their own deployments.

    You can also migrate your self-managed MySQL or Redis databases directly to ApsaraDB RDS. Compared to self-managed databases, ApsaraDB RDS is more secure, reliable, and easier to maintain. For information on migrating a self-managed database to the cloud, see Migrate a self-managed database to a cloud database.

    Situation 2: Session-based services

    If your business service uses sessions to maintain user login status, scaling the service will cause login information (session information) to be inconsistent across service replicas. This can result in users being frequently logged out. To solve this, deploy a separate Redis instance for shared session management.

    Situation 3: Non-concurrent scheduled tasks

    If your business has a scheduled task that must run only once a day, scaling out will cause multiple servers to execute the task at the same time. You may need to adjust your task processing logic to handle this situation.

  • Phase 2: Evolve to a highly available architecture

    After separating the data storage and business logic on the ECS instance, you can scale out by creating replicas of the instance and its business service.

    Migrate the service cluster to a scaling group to leverage its elasticity for rapid replication. Use a load balancer as the access point for the service cluster to distribute the load, ensuring system stability and efficiency.

Quick migration to a highly available architecture

Solution overview

If you have already separated your data storage from your business logic (made it stateless), you can follow these steps to quickly migrate your service from a monolithic architecture to an elastic and highly available architecture using a scaling group.

  1. Deploy a demo website (prepare an instance). This solution simulates a stateless demo web service instance to demonstrate the migration process. You can also use an existing instance.

  2. Build an instance image that contains the business service. This image will be used to launch instances in your cluster, automatically starting the business service upon startup.

  3. Create a scaling group to manage the service cluster. You will use this scaling group to quickly replicate instances (scale out).

  4. Set up a unified access point for the cluster. Associate a load balancer to create a unified access point.

  5. Scale out instances (verification). Quickly replicate instances and access the load balancer to verify that the cluster is working correctly.

1. Deploy a demo website

First, you need an application instance that represents your production environment. This instance will be used for replication and automated deployment.

This tutorial provides a demo website service that you can use to experience the migration process. Click Deploy Demo Service to set up the demo service.

This demo website service includes a web service package, its runtime environment, and a startup script. The instance has already been made stateless by separating its data storage from its business logic.
If your business service instance is already stateless and has the required components (software package, environment, startup script), you can use your actual service instance instead for the following migration steps.

Demo service deployment

As shown in the figure on the right, the ECS instance in this demo architecture contains a web service that connects to a database. Accessing the service's address displays the current server's IP and a string queried from the database. A startup command is configured for this service, so it runs automatically when the ECS instance starts.

The Deploy Demo Service feature uses Resource Orchestration Service (ROS). Using this feature creates a Virtual Private Cloud (VPC) and a vSwitch, an ECS instance with the demo service, and an ApsaraDB RDS for MySQL instance in your Alibaba Cloud account.
image

Follow these steps to deploy the demo service instance:

  1. Click the Deploy Demo Service button to go to the One-click Deployment page.

  2. Follow the on-screen instructions to select a Region and an Zone.

  3. In the instance configuration section, select an Instance Type and set the Instance Password.

    You can select the lowest configuration, such as a burstable instance, to save costs for this tutorial. The available instance types vary by region and availability zone. Refer to the options displayed on the page.
  4. Select an RDS Instance Type and set the RDS Database Password.

  5. After confirming the cost, click Deploy Now and wait for the resources to be created.

    You can monitor the progress on the Specific Resources tab. The resources to watch, in order of creation, are the security group, VPC, vSwitch, ECS instance, and ApsaraDB RDS instance.
  6. On the View Outputs tab, find the link for WebUrl.

    You can visit this link in your browser multiple times. Each time, you will see the same IP address, confirming that you are accessing the same ECS instance.

2. Build an instance image

To ensure that new instances have the business service and startup script, create a custom image from the prepared instance. Subsequent instances will use this as their base image, so your business service will start automatically when the instances launch.

  1. Go to the ECS console and switch to the region where you prepared the instance in Step 1.

  2. Find the ECS instance prepared in Step 1. In the Actions column on the right, choose Disks and Images > Create Custom Image.

  3. In the Create Custom Image dialog box, enter an image name for easy identification, and then click OK. Wait for the image creation to complete. You can check the progress by clicking Instances & Images > Image in the left-side navigation pane of the ECS console.

3. Create a scaling group

Using a scaling group to manage your service cluster is the core of an elastic and highly available architecture. You can use a scaling group to quickly replicate instances. Follow these steps to create and enable a scaling group:

  1. Go to the Scaling Groups page.

    1. Log on to the Auto Scaling console.

      If this is your first time using Auto Scaling, follow the on-screen instructions to grant the necessary permissions. For more information, see Service-linked roles.

    2. In the left-side navigation pane, click Scaling Groups.

    3. In the top navigation bar, select the region where Auto Scaling is activated.

  2. Create a scaling group.

    1. On the Scaling Groups page, click Create to open the Create page.

    2. Complete the following configurations on the page. You can keep the default values for any settings not mentioned in the table.

      Parameter

      Description

      Scaling Group Name

      Enter a name as prompted. In this example, the name is ess-demo.

      Type

      Select ECS.

      Instance Configuration Source

      Select Select Existing Instance.

      Select Existing Instance

      Select the ECS instance prepared in Step 1.

      Minimum Number of Instances

      The minimum number of instances in the scaling group. If the number of instances falls below this value, an automatic scale-out event is triggered. In this example, the minimum is 0.

      Maximum Number of Instances

      The maximum number of instances in the scaling group. If the number of instances exceeds this value, an automatic scale-in event is triggered. In this example, the maximum is 10.

      VPC and vSwitch

      These settings are automatically populated based on the ECS instance you select.

      Important

      We recommend that you create and select vSwitches in multiple availability zones. This helps prevent scaling failures caused by insufficient instance inventory in a single availability zone. To create a vSwitch, see Create a vSwitch.

      Show Advanced Settings > Enable Expected Number of Instances

      Select to enable this feature. After enabling it, you can automatically scale in or out by setting the expected number of instances.

      Show Advanced Settings > Expected Number of Instances

      Enter 0 to create an empty scaling group initially.

      Show Advanced Settings > Instance Health Check

      Select Instance Status Check and Load Balancer Health Check. When enabled, the system uses health check results to ensure that all instances in the scaling group and their business services are running correctly. If a service becomes unhealthy, it is promptly replaced with a new instance.

    3. Click Create and wait for the scaling group to be created.

  3. Modify the instance image in the scaling configuration.

    When you create a scaling group by selecting an existing instance, a scaling configuration is created based on the instance's original image. The original image of the instance created in Step 1 does not include the application package deployed later. Therefore, you need to update the base image in the scaling configuration to the new image created in Step 2.
    1. On the Scaling Groups page, find the scaling group you just created. In the Actions column, click View Details to go to the scaling group's details page.

    2. On the Instance Configuration Source > Scaling Configurations tab, find the only scaling configuration and click Edit Image in the Actions column.

    3. In the Edit Image dialog box, select User-Defined Image. Follow the prompts to select the image you created in Step 2. Click OK to complete the modification.

  4. Enable the scaling group.

    On the Scaling Groups page, click the Enable button in the upper-right corner to activate the scaling group.

4. Set up a unified access point

When scaling from one instance to many, you need a unified access point for the cluster. To do this, create and associate a load balancer with your scaling group. This allows user requests to be automatically distributed across the ECS instances in the cluster, balancing the load and maximizing resource utilization. This example uses an Application Load Balancer (ALB). Follow these steps:

4.1 Create a load balancer

  1. Log on to the ALB console.

  2. On the Instance page, click Create Application Load Balancer.

  3. On the Application Load Balancer (Pay-As-You-Go) purchase page, follow the on-screen instructions to create the ALB.

    This example uses the following configurations. You can keep the default values for any settings not mentioned.

    Parameter

    Description

    Region

    Select the same region as the instance from Step 1.

    Network Type

    Select Internet.

    VPC

    Select the VPC of the instance prepared in Step 1.

    Zone

    Select at least two. If a selected availability zone does not have a vSwitch, follow the on-screen instructions to create one. For instructions on how to create a vSwitch, see Create a vSwitch.

4.2 Create a server group

This server group will be associated with the scaling group. Instances created by the scaling group will be automatically added to this server group to provide services through the load balancer.

  1. In the Application Load Balancer (ALB) console, select a region.

  2. In the left-side navigation pane, click Server Group to go to the Server Groups page. Click Create Server Group and follow the on-screen instructions to create the server group.

    This example uses the following configurations. You can keep the default values for any settings not mentioned.

    Parameter

    Description

    Server Group Type

    Select Server Type.

    Server group name

    Enter a name as prompted. This example uses ess-test-server-group.

    VPC

    Select the VPC of the instance prepared in Step 1.

4.3 Configure a listener

Create an HTTP listener to forward requests from the HTTP protocol. When the load balancer instance receives an HTTP request, it can forward the request to the ECS instances in the server group.

  1. In the Application Load Balancer (ALB) console, select a region.

  2. In the left-side navigation pane, click Instance. Find the load balancer created in Step 4.1 and click Create Listener in the Actions column. Follow the on-screen instructions to create the listener.

    This example uses the following configurations. You can keep the default values for any settings not mentioned.

    Parameter

    Description

    Select listener protocol

    Select HTTP.

    Listener port

    The port on which the load balancer provides services. The demo service uses port 80, which means the listener will handle requests to port 80 of the load balancer.

    Select server group

    Select the server group created in Step 4.2.

4.4 Associate the load balancer

  1. On the Scaling Groups page, find the scaling group you created in Step 3. In the Actions column, click View Details to go to the scaling group's details page.

  2. On the Basic Information tab, find Associated ALB/NLB Server Groups. Click Add Associated ALB/NLB Server Group. In the dialog box that appears, click Add Server Group and follow the prompts to associate the server group created in Step 4.2. After configuring, click OK to complete the association.

    Important

    The port number in this configuration should be the port on which your business service provides services. The demo service in this example uses port 80.

5. Scale out and verify

After configuring the scaling group and associating it with a load balancer, you can scale out instances to verify that the cluster works correctly.

  1. Trigger a scale-out event for the scaling group, and the scaling group will automatically create instances.

    You can trigger a scale-out event by modifying the Desired Capacity for the scaling group. Follow these steps:

    1. On the Scaling Groups page, find the scaling group you just created. In the Actions column, click View Details to go to the scaling group's details page.

    2. On the Basic Information tab, find Instance Scaling Overview and click image. In the Edit Instance Scaling Overview dialog box, change the Expected Number of Instances from 0 to 3 (meaning the cluster needs 3 ECS instances to provide services). Click OK to apply the change.

    3. Wait for the instances to be created. Three ECS instances will be created in the scaling group. You can check the creation status on the Instances tab.

  2. Access the load balancer's address to verify that it is routing requests to the new instances.

    1. Go to the Application Load Balancer (ALB) console.

    2. Find the load balancer created in Step 4.1. Under DNS Name, find the access URL.

    3. Visit this URL multiple times. You should see different IP addresses, which confirms that you can access different servers through the load balancer.

6. (Optional) Clean up resources

If you no longer need the cluster, you can follow this process to clean up the resources.

  1. Release the load balancer created in Step 4.1. For more information, see Release an ALB instance.

  2. Delete the scaling group created in Step 3. For more information, see Delete a scaling group.

  3. Delete the server group created in Step 4.2. For more information, see Create and manage server groups.

  4. Delete the custom image created in Step 2. For more information, see Delete a custom image.

  5. Delete the vSwitches you created in Step 3 and Step 4.1. For more information, see Create and manage a VPC and Delete a vSwitch.

  6. Clean up the demo service deployed in Step 1. If you deployed the demo service from Step 1, you can delete its ROS stack. When deleting the stack, select Release Resources as the Deletion Method to clean up the resources created by the demo service. For more information, see Delete a stack.

Next steps

Before you go live

To ensure this elastic and highly available solution runs stably in a production environment, we recommend that you complete the following actions before you go live:

  • Refine the scaling group configuration

    • Implement multi-zone disaster recovery: You can configure vSwitches in multiple availability zones for your scaling group and set a Multi-zone Scaling Policy. This allows the scaling group to create instances across multiple availability zones and distribute service instances evenly among them, improving the scaling success rate and the cluster's disaster recovery capability. For more information, see Scaling policies.

    • Select multiple instance types: A scale-out event may fail if a single instance type is out of stock. You can select multiple instance types to improve the scaling success rate. For more information, see Create a scaling configuration (ECS instances).

  • Conduct thorough testing

    If you plan to use this elastic and highly available solution in a production environment, we recommend that you conduct tests after setting up the cluster. This ensures that your service works correctly when replicated and allows you to perform stress tests on the cluster to estimate your resource needs.

Use a domain name for access

Update DNS records

If you previously used a domain name to access your ECS instance, you can update your domain's DNS records to point to your load balancer. This way, when users access the domain, their requests will be routed through the load balancer to your service cluster. For more information, see Configure CNAME resolution for an ALB instance.

Important

After you update DNS, propagation takes time. Do not change the original service IP address or stop the original instance immediately. Keep the original ECS instance running for a while. Monitor its inbound traffic and stop it only after the traffic drops to zero.

This avoids service interruptions for users whose local DNS cache still points to the original IP address.

HTTPS protocol support

This example uses HTTP. To enable HTTPS for your cluster's domain, configure an HTTPS listener for the load balancer. For more information, see Add an HTTPS listener.

Use Auto Scaling features

  • Design a scaling strategy: This tutorial does not cover the design of automatic scaling strategies. You can set up automatic scaling for your scaling group later to optimize costs. To learn how to design a scaling strategy, see Supported scaling strategies.

  • Advanced features: If you have more advanced requirements for your scaling group, such as improving scaling success rates or further reducing costs, see Advanced features.