DEV Community

Anupa Supul
Anupa Supul

Posted on

Why Doesn't My Website Crash When Thousands of People Visit? Understanding Amazon EC2

When I first started learning AWS, I assumed that if a website became popular, the solution was simple.

Buy a bigger server.

More CPU.

More RAM.

More storage.

Problem solved.

But then I started thinking about websites like Netflix, Amazon, and Instagram.

Millions of people visit them every day.

Sometimes millions of users are online at exactly the same time.

Surely they don't keep buying one giant server every time traffic increases.

So how do they handle sudden spikes in visitors without crashing?

That question introduced me to Amazon EC2 Auto Scaling.


The Problem

Imagine I build my own portfolio website.

Normally, around 100 people visit it each day.

Everything works perfectly.

Then one day, someone with a huge social media following shares my website.

Within minutes...

10,000 people try to open it.

What happens?

If I only have one EC2 instance, that single server now has to handle every request.

Soon it becomes overloaded.

Pages load slowly.

Some users get errors.

Eventually...

The website crashes.

flowchart LR

Users --> EC2

style EC2 fill:#ff9999
Enter fullscreen mode Exit fullscreen mode

Clearly, one server isn't enough.


My First Thought

My first solution was:

Just buy a bigger server.

For example:

Upgrade from

  • 2 GB RAM

to

  • 16 GB RAM

This is called Vertical Scaling.

flowchart LR

SmallEC2["Small EC2"]

-->LargeEC2["Bigger EC2"]
Enter fullscreen mode Exit fullscreen mode

This works...

But only up to a point.

Eventually, even the biggest server has limits.


AWS Had a Better Idea

Instead of buying one huge server...

Why not create more servers whenever they're needed?

That's exactly what Auto Scaling does.

Instead of this:

flowchart LR

Users --> OneServer
Enter fullscreen mode Exit fullscreen mode

AWS can do this:

flowchart LR

Users

-->ELB

ELB-->EC21

ELB-->EC22

ELB-->EC23

ELB-->EC24
Enter fullscreen mode Exit fullscreen mode

Now the workload is shared across multiple EC2 instances.

Each server handles only part of the traffic.


What Is Amazon EC2 Auto Scaling?

Amazon EC2 Auto Scaling automatically launches or removes EC2 instances depending on your application's traffic.

Simply put:

  • More visitors ➜ More servers

  • Fewer visitors ➜ Fewer servers

No manual work required.


Scale Out

Suppose your website suddenly becomes popular.

Traffic increases.

Auto Scaling detects the increase.

It automatically launches additional EC2 instances.

flowchart LR

Traffic

-->AutoScaling

AutoScaling

-->EC21

AutoScaling

-->EC22

AutoScaling

-->EC23

AutoScaling

-->EC24
Enter fullscreen mode Exit fullscreen mode

This process is called Scale Out.


Scale In

Now imagine it's midnight.

Most users leave.

You no longer need four servers.

Keeping them running would waste money.

Auto Scaling automatically terminates the extra EC2 instances.

flowchart LR

TrafficDrops

-->AutoScaling

AutoScaling

-->EC21
Enter fullscreen mode Exit fullscreen mode

This is called Scale In.

You only pay for what you actually use.


Auto Scaling Group

Auto Scaling doesn't create random servers.

Instead, it manages them inside something called an Auto Scaling Group (ASG).

An ASG follows rules that you define.

For example:

  • Minimum Instances → 2

  • Desired Instances → 3

  • Maximum Instances → 10

If traffic increases, AWS can grow from:

3 → 4 → 5 → 6 → ... → 10
Enter fullscreen mode Exit fullscreen mode

If traffic decreases, it can shrink back down.

Everything happens automatically.


Auto Scaling + Elastic Load Balancer

One thing finally clicked for me.

Auto Scaling creates servers.

But...

How do users know which server to use?

That's where the Elastic Load Balancer (ELB) comes in.

flowchart LR

Users

-->ELB

ELB-->EC21

ELB-->EC22

ELB-->EC23

ELB-->EC24
Enter fullscreen mode Exit fullscreen mode

The Load Balancer distributes traffic.

Auto Scaling creates or removes servers.

Together, they make applications highly available.


Real-World Examples

Auto Scaling is useful almost everywhere.

Imagine:

  • Black Friday shopping
  • Concert ticket sales
  • Online gaming events
  • Netflix releasing a new season
  • Viral social media applications

Traffic suddenly increases.

Instead of crashing...

AWS automatically adds more servers.

Once traffic drops, it removes the extra servers.


Why This Saves Money

Without Auto Scaling, you might keep ten servers running all day.

Even when only one server is needed.

That's expensive.

With Auto Scaling:

Busy hours:

8 Servers
Enter fullscreen mode Exit fullscreen mode

Quiet hours:

2 Servers
Enter fullscreen mode Exit fullscreen mode

AWS adjusts automatically.

You only pay for the servers you actually need.


Benefits of Auto Scaling

Handles sudden traffic spikes

Improves application availability

Prevents server overload

Automatically adds or removes EC2 instances

Reduces infrastructure costs

Works seamlessly with Elastic Load Balancers


What Changed My Perspective

Before learning Auto Scaling, I thought handling more users meant buying a more powerful server.

Now I understand that's only one approach.

Sometimes the better solution isn't:

A bigger server.

It's:

More servers working together.

That small mindset shift completely changed how I think about scalable applications.


Final Thoughts

When I first heard the term Amazon EC2 Auto Scaling, I imagined it was just another AWS feature.

Now I realize it's one of the key reasons modern cloud applications stay online during sudden traffic spikes.

Instead of guessing how many servers you'll need...

AWS watches your traffic for you.

When demand increases, it automatically adds more servers.

When demand decreases, it removes the extras.

That's one of the biggest advantages of cloud computing.

You don't have to build for your busiest day.

AWS scales with you.


Key Takeaways

  • Auto Scaling automatically launches and removes EC2 instances.
  • Scale Out adds more servers during high traffic.
  • Scale In removes servers when traffic decreases.
  • Auto Scaling Groups manage EC2 instances using rules.
  • Elastic Load Balancer distributes traffic across all instances.
  • Together, ELB and Auto Scaling build highly available applications.

*Thanks for reading! *

Top comments (0)