Auto Scaling is easy to describe and hard to picture. You read about launch templates, scaling policies, target tracking and CloudWatch alarms, but until you watch a group of servers grow under load and shrink again, it stays theoretical. So I built a small but realistic setup on AWS and pushed traffic at it with Locust (a stress tool like stress works too) to see Auto Scaling react in real time.
The architecture

Traffic flows Route 53 → Application Load Balancer → Auto Scaling group → EC2 instances. The application is a small Python Flask app, and its data lives in a MySQL database on Amazon RDS, not on the instances. That last decision turned out to be the most important one in the project.
Vertical vs horizontal scaling
There are two ways to handle more load. Vertical scaling means making one server bigger, for example moving from a t2.micro to a t3.large. It’s simple, but it usually needs a restart, there’s a ceiling on how big an instance can get, and you still have a single server that can fail.
Horizontal scaling means adding more servers, say going from two instances to four, and spreading traffic across them. It has no hard ceiling and survives individual servers failing. That’s what Auto Scaling does, and it’s how most cloud applications handle load.
Keep the instances stateless
If your application writes data to the EC2 instance’s own disk, Auto Scaling becomes a problem. Instances are created and terminated automatically, and when one goes, its data goes with it. A user’s data might also end up on a different server from the one their next request reaches.
The solution is to keep compute and data separate. The EC2 instances only run the application, and anything that must persist goes to RDS (and files to S3, if you have them). Any instance can then be replaced at any time without losing anything.
Preparing the application and the AMI
I started with one instance: cloned the repository, installed the dependencies with pip install -r requirements.txt, configured Flask, and created a systemd service so the app starts automatically on boot. That last part matters, because Auto Scaling launches instances with nobody there to start the app by hand.
Once that instance worked, I created an AMI (Amazon Machine Image) from it. Every instance Auto Scaling launches starts from this image, so they’re all identical.
Launch template and Auto Scaling group
The launch template tells Auto Scaling how to build a new instance: which AMI, which instance type, which security groups, and any startup configuration. The Auto Scaling group uses that template and keeps the number of instances within the limits you set:
| Setting | Value |
|---|---|
| Desired Capacity | 2 |
| Minimum Capacity | 1 |
| Maximum Capacity | 4 |
With these settings, two instances run normally, and AWS can add up to two more during heavy traffic, then remove them again when things calm down. The group is attached to the load balancer’s target group, so new instances start receiving traffic as soon as they pass the health check.
Scaling policies
The first policy I used was target tracking on average CPU utilisation, with a target of 40%. You tell AWS the number you want to stay around, and it adds or removes instances to keep the group there. For most applications this is the right place to start.
I also tried step scaling with CloudWatch alarms and SNS notifications. Step scaling lets you respond differently depending on how far a metric goes past the threshold. For example, you can add one instance at 60% CPU and three at 85%. It’s more work to configure, but it gives you finer control.
Watching it scale
With Locust sending more and more concurrent requests, you can watch the chain happen: CPU rises on the two instances, the CloudWatch metric crosses the target, Auto Scaling launches new instances, they register with the load balancer and start taking traffic, and average CPU drops back down. Seeing that live made the concept much clearer to me than any diagram.
Breaking things on purpose
Then I tried to break it. I terminated instances while traffic was running, restarted the database service and threw sudden traffic spikes at it. The application kept serving requests. The load balancer stopped sending traffic to unhealthy instances, Auto Scaling replaced the ones I terminated, and because the data lived in RDS, nothing was lost. That’s the moment the setup stopped feeling like a lab and started feeling like real infrastructure.
What went wrong along the way
Most problems in a setup like this come from small misconfigurations. A security group that doesn’t allow the load balancer to reach the instances, health checks pointing at the wrong path or port, a target group on the wrong port, or a scaling policy so aggressive that it adds and removes instances constantly. Any one of them can stop scaling entirely or mark healthy instances as unhealthy, so check these first when something doesn’t behave.
Clean up when you’re done
This project creates several things that charge by the hour: EC2 instances, the load balancer and the RDS database. When you finish, delete the Auto Scaling group first (otherwise it will keep replacing the instances you terminate), then the load balancer, then the RDS instance if you don’t need it.
Full walkthrough
The video covers Route 53, the load balancer, the launch template and Auto Scaling group, RDS, the Flask deployment, CloudWatch alarms and the Locust load test, with scaling shown live.
Try it yourself
Deploy a simple app, put a load balancer in front of it, add an Auto Scaling group, then generate traffic and watch. After that, the same ideas carry over to Kubernetes with the Horizontal Pod Autoscaler, ECS service scaling, Spot Instances for cheaper capacity, and blue/green deployments. If you want to protect the same setup from attacks, AWS WAF fits in front of the load balancer, and WordPress on AWS with ALB and SSL shows the load balancer side in more detail.

1 response