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)