DEV Community

Cover image for Day 9 πŸš€ Load Balancing + Auto Scaling in AWS | How To Work And Use
Sudarshan Yadav
Sudarshan Yadav

Posted on

Day 9 πŸš€ Load Balancing + Auto Scaling in AWS | How To Work And Use

πŸ“… Day 9 πŸš€ Load Balancing + Auto Scaling in AWS | How To Work And Use

In real-world applications, traffic is not always constant. Sometimes we get high traffic (festive sale, new feature release) and sometimes traffic is very low.

To handle this automatically, AWS provides two major services:


πŸ”Ή 1️⃣ Load Balancing (ELB – Elastic Load Balancer)

Load Balancer acts like a traffic manager. It receives all incoming traffic and distributes it across multiple servers (EC2 instances).

🎯 Key Purposes:

  • Avoids overload on any single server
  • Ensures High Availability
  • Provides Fault Tolerance
  • Continues to work even if one server fails

🧠 How it Works?

  • Users send requests β†’ Load Balancer receives them
  • It checks backend servers (health checks)
  • Sends traffic only to healthy servers
  • If a server fails β†’ traffic moves to other servers automatically

πŸ“Œ Types of Load Balancers in AWS:

  • Application Load Balancer (ALB) – Layer 7 (HTTP/HTTPS)
  • Network Load Balancer (NLB) – Layer 4 (TCP/UDP)
  • Classic Load Balancer (CLB) – Old generation

πŸ”Ή 2️⃣ Auto Scaling (ASG – Auto Scaling Group)

Auto Scaling automatically adds or removes EC2 instances depending on the load.

🎯 Benefits:

  • Handles traffic spikes automatically
  • Reduces cost (shuts down unnecessary servers)
  • Ensures continuous performance
  • Self-healing β†’ failed instances are replaced automatically

🧠 How it Works?

  • CloudWatch monitors the application load (CPU, memory, network traffic)
  • If load increases ↑ β†’ Add new EC2 instances
  • If load decreases ↓ β†’ Terminate extra EC2 instances

πŸ”₯ Load Balancer + Auto Scaling Together

When both work together, they create a powerful architecture:

Feature Who Handles It?
Distribute traffic Load Balancer
Add/remove EC2 instances based on demand Auto Scaling
Replace failed servers Auto Scaling
Redirect traffic to only healthy servers Load Balancer

Benefits:

βœ” High Performance

βœ” High Availability

βœ” Zero Downtime

βœ” Cost Optimization

βœ” Better User Experience


🧩 Real Example

If an e-commerce website gets huge traffic during sale:

  • Auto Scaling launches more EC2 instances
  • Load Balancer distributes traffic to all servers

When sale ends and traffic drops:

  • Auto Scaling removes extra EC2 instances
  • Cost gets reduced automatically

πŸ›  Architecture Diagram

                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚        Users         β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β”‚
                                 β–Ό
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚   Load Balancer      β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    /            β”‚            \
                   β–Ό             β–Ό             β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚  EC2-1   β”‚  β”‚  EC2-2   β”‚  β”‚  EC2-3   β”‚   ← Auto Scaling Group
            β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                  β”‚             β”‚             β”‚
                  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                        β–Ό               β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚     CloudWatch Metrics     β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚    Auto Scaling Policy     β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

## Thank You

πŸ”— Connect With Me

🌐 Platform πŸ”— Link
πŸ™ GitHub https://lnkd.in/d2F3JPa3
✍️ Dev.to Blog https://lnkd.in/dNtgqAME
πŸ’Ό LinkedIn https://lnkd.in/d3NctxFT
πŸ“„ Resume (Google Drive) https://lnkd.in/dHDNsd_D

πŸ”– Hashtags

AWS #DevOps #CloudComputing #AWSLearning #EBS #VolumeMounting #DataPersistence #LearningJourney #CareerGrowth #DevOpsEngineer #AWSCommunity

Top comments (0)