
๐ Day 13/30: Auto Scaling โ How Does AWS Automatically Add & Remove Servers? โ๏ธ
Discover how Auto Scaling helps our college examination portal handle sudden traffic spikes by automatically adjusting EC2 capacity. ๐ Learn about Auto Scaling Groups, scaling out and in, health checks, launch templates, and how Auto Scaling works with Load Balancers to keep applications reliable and efficient.
Series: Cloud Computing (24 articles)
- โฆ
- 14๐ Day 13/30: Auto Scaling โ How Does AWS Automatically Add & Remove Servers? โ๏ธ This article
๐ Day 13/30: Auto Scaling โ How Does AWS Automatically Add & Remove Servers? โ๏ธ
๐ฎ Mission 13: The Portal That Scales Itself!
Yesterday was crazy.
At 9:00 AM, thousands of students opened the college examination portal at the same time. ๐ฑ
Our Load Balancer saved the day.
Instead of sending every request to one server, it distributed traffic across multiple EC2 instances.
Our architecture looked like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
๐จโ๐ ๐ฉโ๐ ๐จโ๐ ๐ฉโ๐
|
v
โ๏ธ Load Balancer
|
+-----------+-----------+
| | |
v v v
EC2-1 EC2-2 EC2-3
| | |
+-----------+-----------+
|
v
DatabaseThe portal survived.
Everyone could register.
Rahul smiled.
But at 2:00 PMโฆ
The traffic dropped.
Now only a few students were using the portal.
And our college was still running all those EC2 servers.
Rahul asked:
โWhy should we keep paying for servers we don't currently need?โ
๐ค
Then the cloud architect smiled.
โThat's exactly what Auto Scaling is designed to help with.โ
Welcome to Day 13.
Today, we're teaching our cloud architecture how to adapt to changing demand automatically.
๐ค 1. What Is Auto Scaling?
In simple words:
Auto Scaling means automatically adjusting the number of compute resources according to demand and your scaling configuration.
Instead of manually doing this:
1
2
3
4
5
6
7
8
9
Traffic increases
โ
Admin notices
โ
Admin launches more servers
โ
Admin configures them
โ
Servers join applicationWe want something closer to:
1
2
3
4
5
6
7
8
9
Traffic increases
โ
Scaling policy triggers
โ
More EC2 instances launch
โ
Instances become healthy
โ
They can receive trafficAnd when demand falls:
1
2
3
4
5
6
7
Traffic decreases
โ
Scaling policy triggers
โ
Extra instances are removed
โ
Application continues runningThat's the basic idea behind Amazon EC2 Auto Scaling.
๐ซ 2. Imagine Our College Has Smart Registration Counters
Let's return to our college.
Imagine there are registration counters.
At 8 AM:
1
2
3
4
๐จโ๐ ๐ฉโ๐
๐จโ๐
2 counters are enough.At 9 AM:
1
2
3
4
๐จโ๐ ๐ฉโ๐ ๐จโ๐ ๐ฉโ๐ ๐จโ๐ ๐ฉโ๐ ๐จโ๐
๐ฉโ๐ ๐จโ๐ ๐ฉโ๐ ๐จโ๐ ๐ฉโ๐
We need more counters!At 2 PM:
1
2
3
๐จโ๐ ๐ฉโ๐
We don't need all those counters anymore.A smart college administration system could automatically open additional counters during busy periods and close unnecessary ones later.
That's the mental model for Auto Scaling.
๐งฉ 3. Meet the Auto Scaling Group
The main building block we'll use is an Auto Scaling Group (ASG).
Think of an Auto Scaling Group as a manager responsible for a group of EC2 instances.
It helps maintain the desired number of instances within configured limits.
For example:
1
2
3
Minimum capacity: 2
Desired capacity: 3
Maximum capacity: 6This means our group is configured so that:
- It should not normally go below 2 instances.
- It currently wants 3 instances.
- It should not automatically scale beyond 6 instances under that configuration.
So our application might begin like this:
1
2
3
4
5
6
Auto Scaling Group
|
+------------+------------+
| | |
v v v
EC2-1 EC2-2 EC2-3Now traffic increases.
The scaling configuration determines that more capacity is needed.
The group can launch additional instances:
1
2
3
4
5
6
Auto Scaling Group
|
+-------+-------+-------+-------+
| | | | |
v v v v v
EC2-1 EC2-2 EC2-3 EC2-4 EC2-5Our application has more compute capacity available.
๐ฏ 4. Desired, Minimum and Maximum Capacity
These three numbers are extremely important.
Let's say our college portal uses:
1
2
3
Minimum = 2
Desired = 3
Maximum = 6๐ข Minimum Capacity
The minimum is the smallest number of instances the Auto Scaling Group should maintain under its configuration.
1
2
3
4
Minimum = 2
EC2-1
EC2-2๐ต Desired Capacity
Desired capacity is the number of instances the group currently aims to maintain.
1
2
3
4
5
Desired = 3
EC2-1
EC2-2
EC2-3๐ด Maximum Capacity
Maximum capacity places an upper boundary on automatic scaling.
1
2
3
4
5
6
7
8
Maximum = 6
EC2-1
EC2-2
EC2-3
EC2-4
EC2-5
EC2-6So our cloud architecture has a controlled range:
1
2
3
4
Minimum Maximum
2 6
|------------------------------|
CapacityThis gives us control over both availability and resource usage.
๐ 5. What Happens When Traffic Suddenly Explodes?
It's Monday morning.
The college announces:
โExamination registration closes today!โ
Suddenly:
1
2
3
4
5
6
7
100 users
โ
1,000 users
โ
5,000 users
โ
20,000 usersThe application needs more capacity.
Our architecture can respond according to its scaling configuration.
1
2
3
4
5
6
7
8
9
10
11
12
Students
|
v
โ๏ธ Load Balancer
|
v
Auto Scaling Group
|
+---------+-------+-------+---------+
| | | | |
v v v v v
EC2-1 EC2-2 EC2-3 EC2-4 EC2-5Now the workload can be distributed across more application instances.
The important idea is:
We don't need to manually launch every additional server.
๐ 6. What Happens When Traffic Falls?
Now it's midnight.
Most students are sleeping. ๐ด
Only a few requests are coming in.
Keeping six EC2 instances running may provide capacity we don't currently need.
Our scaling policy can reduce the desired capacity, as long as it remains within the configured limits.
For example:
1
2
3
4
5
6
7
8
Before:
EC2-1
EC2-2
EC2-3
EC2-4
EC2-5
EC2-6After scaling in:
1
2
3
EC2-1
EC2-2
EC2-3The application still has capacity.
But we're no longer running as many instances as during the traffic spike.
This is called scaling in.
๐ 7. Scaling Out vs Scaling In
These two terms are easy to remember.
๐ Scaling Out
Add more instances.
1
2
3
3 EC2 instances
โ
5 EC2 instancesThis is also called horizontal scaling.
๐ Scaling In
Remove instances.
1
2
3
5 EC2 instances
โ
3 EC2 instancesSo:
Scale out = more instances
Scale in = fewer instances
๐ง 8. Why Not Just Buy a Bigger Server?
Excellent question!
Suppose our college portal is running on one very powerful server.
Traffic increases.
We could replace it with an even larger server.
That's called vertical scaling.
1
2
3
4
5
Small Server
โ
Bigger Server
โ
Even Bigger ServerBut there are limits.
Instead, cloud applications often use horizontal scaling:
1
2
3
4
5
One Server
โ
Multiple Servers
โ
More ServersFor many web applications, horizontal scaling provides flexibility and can improve resilience when combined with distributed architecture.
Our college portal can use multiple application instances rather than depending on one giant machine.
โค๏ธ 9. What If an EC2 Instance Suddenly Dies?
Now let's create a problem.
Our Auto Scaling Group has:
1
2
3
EC2-1 โ
EC2-2 โ
EC2-3 โ
EC2-2 crashes.
What should happen?
We don't want the application to permanently lose capacity.
An Auto Scaling Group can use health checks to determine whether instances are healthy.
If an instance is considered unhealthy, the group can terminate and replace it according to its configuration.
So the architecture can move toward:
1
2
3
4
5
Before:
EC2-1 โ
EC2-2 โ
EC2-3 โ
Then:
1
2
3
4
5
6
7
8
9
10
11
Auto Scaling Group
|
| Detects unhealthy instance
v
Replace EC2-2
|
v
Launch replacement
|
v
New healthy instanceEventually:
1
2
3
EC2-1 โ
EC2-2 ๐
EC2-3 โ
This is one of the powerful ideas behind cloud architecture:
The system can automatically recover capacity instead of waiting for a human to notice every failure.
โ๏ธ 10. Auto Scaling + Load Balancer = Powerful Combination
Now let's connect yesterday's lesson with today's lesson.
Yesterday:
Load Balancer
โI'll distribute traffic.โ
Today:
Auto Scaling
โI'll adjust the number of application instances.โ
Together:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
๐จโ๐ ๐ฉโ๐ ๐จโ๐
๐ฉโ๐ ๐จโ๐ ๐จโ๐
|
v
โ๏ธ Load Balancer
|
v
๐ Auto Scaling Group
|
+----------------+----------------+
| | |
v v v
EC2-1 EC2-2 EC2-3
| | |
+----------------+----------------+
|
v
DatabaseNow imagine traffic increases.
1
2
3
4
5
6
7
8
9
10
11
12
13
Traffic โ
|
v
Auto Scaling
|
v
EC2-4 added
|
v
Load Balancer
|
v
New healthy target can receive trafficTraffic decreases.
1
2
3
4
5
6
7
8
9
10
11
Traffic โ
|
v
Auto Scaling
|
v
Extra capacity removed
|
v
Load Balancer
continues serving remaining healthy targetsThis is where our architecture starts becoming truly dynamic.
๐๏ธ 11. But How Does AWS Know How to Launch the Servers?
Here's another important piece.
If AWS needs to launch a new EC2 instance, it needs to know:
โWhat kind of instance should I create?โ
For example:
- Which AMI?
- Which instance type?
- Which security groups?
- Which IAM role?
- Which subnets?
- Which storage configuration?
- Which user data or startup configuration?
Instead of manually configuring every instance, we can define the configuration used to launch instances.
A common approach is an EC2 launch template.
Think of it as a blueprint.
1
2
3
4
5
6
๐ Launch Template
|
+-----------+-----------+
| | |
v v v
EC2-1 EC2-2 EC2-3Every new instance can be created using the defined configuration.
This helps make our servers more consistent.
๐ 12. Spread the Servers Across Availability Zones
Remember our earlier lessons?
We don't want every application server sitting in one Availability Zone if our architecture requires resilience across zones.
Instead:
1
2
3
4
5
6
7
8
9
10
โ๏ธ Load Balancer
|
+---------+---------+
| |
v v
Availability Zone 1 Availability Zone 2
EC2-1 EC2-3
EC2-2 EC2-4Our Auto Scaling Group can be configured to launch instances across selected Availability Zones.
If one zone experiences a problem, the application may still have capacity in another zone, depending on the architecture and remaining resources.
This connects our entire journey:
Regions โ Availability Zones โ Load Balancing โ Auto Scaling
Each concept solves a different part of the architecture problem.
๐ฅ 13. The College Portal Faces Its Biggest Challenge Yet
It's 8:55 AM.
The exam registration deadline is approaching.
Our system currently has:
1
2
3
Desired Capacity = 3
Minimum Capacity = 2
Maximum Capacity = 8At 9:00 AM:
1
2
3
4
5
๐จโ๐ ๐ฉโ๐ ๐จโ๐ ๐ฉโ๐
๐จโ๐ ๐ฉโ๐ ๐จโ๐ ๐ฉโ๐
๐จโ๐ ๐ฉโ๐ ๐จโ๐ ๐ฉโ๐
โ
Traffic increasesOur architecture responds according to its scaling policy.
1
2
3
4
5
6
7
3 instances
โ
4 instances
โ
5 instances
โ
6 instancesThe Load Balancer distributes traffic across healthy targets.
Students continue registering.
Rahul checks his screen.
1
โ
Registration SuccessfulBut this time, Rahul realizes something important:
The cloud architecture didn't just survive the traffic spike.
It adapted to it.
๐ฏ 14. A Simple Auto Scaling Story
Let's summarize the entire process.
1
2
3
4
5
6
7
8
9
10
11
12
13
1๏ธโฃ Users arrive
โ
2๏ธโฃ Load increases
โ
3๏ธโฃ Scaling policy detects the need for more capacity
โ
4๏ธโฃ Auto Scaling Group increases desired capacity
โ
5๏ธโฃ New EC2 instances launch from the configured template
โ
6๏ธโฃ Instances become healthy
โ
7๏ธโฃ Load Balancer sends traffic to healthy targetsAnd when demand drops:
1
2
3
4
5
6
7
8
9
1๏ธโฃ Traffic decreases
โ
2๏ธโฃ Scaling policy determines less capacity is needed
โ
3๏ธโฃ Auto Scaling Group decreases desired capacity
โ
4๏ธโฃ Extra instances are terminated
โ
5๏ธโฃ Remaining healthy instances continue serving usersThat's the basic lifecycle.
๐งช 15. Cloud Architect Challenge
You are now the cloud architect for our college.
Your Auto Scaling Group is configured as:
1
2
3
Minimum = 2
Desired = 4
Maximum = 8Scenario 1
Traffic suddenly increases.
Can the group launch more instances?
Yes, as long as the scaling policy calls for additional capacity and the configured maximum isn't exceeded.
Scenario 2
Traffic decreases significantly.
Can the group scale from 8 instances down to 2?
Potentially yes, depending on the scaling policy and current desired capacity, while respecting the configured minimum.
Scenario 3
One instance becomes unhealthy.
Can the Auto Scaling Group replace it?
Yes, when configured health checks identify it as unhealthy and the group takes corrective action.
Scenario 4
You want every new instance to have the same basic configuration.
What can help?
An EC2 launch template.
๐ง 16. One Important Lesson: Auto Scaling Is Not Magic
Auto Scaling doesn't mean:
โAWS will automatically make my application infinitely scalable.โ
That's not how it works.
We still need to design the application properly.
For example:
- ๐๏ธ Can the database handle the increased traffic?
- ๐พ Is application state stored appropriately?
- ๐ Are permissions correctly configured?
- ๐ Is the network designed correctly?
- โ๏ธ Is the load balancer configured correctly?
- ๐ Are scaling policies appropriate?
- ๐ Are we monitoring the system?
Adding more EC2 instances doesn't automatically solve every bottleneck.
For example:
1
2
3
4
5
6
7
100 EC2 instances
|
v
Tiny Database
|
v
๐ฅ DATABASE BOTTLENECKThe architecture must scale as a system.
That's what cloud architecture is really about.
๐งฉ 17. Look How Far Our Architecture Has Come
Remember Day 1?
We simply asked:
โWhat is cloud computing?โ
Now look at our architecture.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
๐จโ๐ Students
|
v
๐ Internet
|
v
โ๏ธ Load Balancer
|
v
๐ Auto Scaling Group
|
+----------------+----------------+
| | |
v v v
EC2-1 EC2-2 EC2-3
| | |
+----------------+----------------+
|
+-----------+-----------+
| |
v v
๐๏ธ Amazon RDS ๐ชฃ Amazon S3
Student Records Documents & FilesAnd behind this architecture we have already learned:
๐ IAM โ Who can access AWS resources?
๐ VPC โ How does traffic move through the cloud?
โ๏ธ Load Balancer โ Where should requests go?
๐ Auto Scaling โ How many application instances do we need?
๐๏ธ Database โ Where does application data live?
๐ชฃ Storage โ Where do files live?
This is no longer just a collection of AWS services.
It's becoming an architecture.
๐ Mission Complete!
Today, our college portal learned how to adapt.
We started with a simple problem:
โWhat happens when thousands of users arrive?โ
And discovered:
โ๏ธ Load Balancing
Distributes requests across application targets.
๐ Auto Scaling
Adjusts application capacity according to scaling policies and configured limits.
๐ Launch Templates
Provide a repeatable configuration for launching EC2 instances.
โค๏ธ Health Checks
Help identify unhealthy instances so capacity can be maintained.
๐ Multiple Availability Zones
Help distribute application capacity for greater resilience.
The result?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
TRAFFIC CHANGES
|
v
๐ Auto Scaling
|
+------+------+
| |
v v
More EC2 Fewer EC2
when needed when needed
| |
+------+------+
|
v
โ๏ธ Load Balancer
|
v
Users Happy ๐๐ Coming Up on Day 14/30
๐ Content Delivery & CDN โ Why Does a Website Feel Faster When Content Is Closer to You?
Our college portal is now scalable.
But Rahul notices something strange.
The application works perfectly, yet students in another city are complaining:
โThe portal is loading slowly!โ
Why?
Because every image, CSS file, JavaScript file, and other static asset may have to travel a long distance to reach the user.
What if we could bring frequently requested content closer to users around the world? ๐
That's where our next mission begins.
Day 14 will explore:
- ๐ What is a Content Delivery Network?
- โก How does a CDN make websites faster?
- ๐ฆ What is caching?
- ๐ What is Amazon CloudFront?
- ๐บ๏ธ How does content get served from locations closer to users?
- ๐ง What should be cached โ and what should not?
- ๐ซ How can our college portal deliver images, CSS, JavaScript, and other static content faster?
Our architecture is about to move from:
โHow do we handle more users?โ
to:
โHow do we serve those users faster?โ
โ๏ธ Build it. Secure it. Scale it. Accelerate it.
#CloudComputing #AWS #CloudArchitecture #AutoScaling #AmazonEC2 #AWSCloud #30DaysOfCloud
Series: Cloud Computing (24 articles)
- โฆ
- 14๐ Day 13/30: Auto Scaling โ How Does AWS Automatically Add & Remove Servers? โ๏ธ This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article