AWS Builder Center
How I Built a Scalable Full-Stack Application on AWS Using EC2 Auto Scaling and an Application Load Balancer

How I Built a Scalable Full-Stack Application on AWS Using EC2 Auto Scaling and an Application Load Balancer

A hands-on AWS project exploring how to scale a full-stack application using Amazon EC2, Application Load Balancer, and Auto Scaling. The application uses Next.js, NestJS, and PostgreSQL. I configured an Auto Scaling Group, tested traffic using a load-testing tool, and monitored how AWS responds to increased traffic. This project helped me better understand load balancing, scaling policies, health checks, and CloudWatch metrics.

Full Stack Developer
Recently, I set up a small full-stack application on AWS to understand how an application can scale automatically when traffic increases.
My application uses:
  • Next.js for the frontend
  • NestJS for the backend
  • PostgreSQL for the database
I deployed the application on Amazon EC2 and used an Application Load Balancer (ALB) together with an Auto Scaling Group to make the infrastructure more scalable and highly available.

The Architecture

The main idea was straightforward:
Users
↓
Application Load Balancer
↓
Auto Scaling Group
↓
EC2 Instances running the application

The Application Load Balancer receives incoming traffic and distributes it across healthy EC2 instances.
The Auto Scaling Group manages the EC2 instances. I configured a minimum capacity of 1 instance and a maximum capacity of 4 instances. When the configured scaling conditions are met, AWS can automatically launch additional EC2 instances. When traffic decreases, it can also reduce the number of running instances based on the scaling policy.

My Setup

The application was deployed using EC2 launch templates so that new instances could start with the required configuration.
The important AWS components were:
  • Amazon EC2
  • Launch Template
  • Auto Scaling Group
  • Application Load Balancer
  • Target Group
  • CloudWatch monitoring and metrics
The Auto Scaling Group keeps the desired number of instances running, while the ALB routes requests only to healthy targets.

Testing the Auto Scaling

To test the setup, I sent a large number of requests to the Application Load Balancer using the  hey  load testing tool.
The goal was to simulate increased traffic and monitor how the infrastructure responded.
One thing I learned during the test is that simply setting the maximum capacity to 4 does not automatically create four instances.
For example:
Minimum capacity: 1
Desired capacity: 1
Maximum capacity: 4

This only defines the allowed range. A proper scaling policy is still required to tell AWS when to increase or decrease the number of instances.
Another important lesson was choosing the right scaling metric. A simple Nginx or lightweight web application may not use much CPU even when handling many requests. Because of that, CPU-based scaling might not always trigger during testing.
Using metrics related to Application Load Balancer traffic, such as request count per target, can be more useful for this type of experiment.

What I Learned

This project gave me a much better understanding of how AWS handles scalable infrastructure.
I learned how:
  • An Application Load Balancer distributes incoming traffic
  • Target Groups perform health checks on instances
  • Auto Scaling Groups maintain the desired capacity
  • Scaling policies decide when to add or remove instances
  • CloudWatch metrics help monitor infrastructure performance
  • Launch Templates make it easier to create consistently configured EC2 instances

Final Thoughts

This was a hands-on learning project, but it helped me understand an important part of modern cloud infrastructure.
Building an application is only one part of the process. The infrastructure also needs to handle increasing traffic, failures, and changing workloads.
AWS Auto Scaling and Application Load Balancers make it possible to build systems that can respond dynamically instead of manually launching and managing every server.
My next step is to improve this architecture further by adding better monitoring, deployment automation, and a more production-ready database setup.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article