Elastic Load Balancing & Auto Scaling in AWS
Mastering Scalability, High Availability, and Fault Tolerance
In this chapter, weβll take a deep dive into two essential AWS servicesβElastic Load Balancing (ELB) and Auto Scalingβwhich are foundational for building scalable, reliable, and resilient cloud applications.
Part 1: Elastic Load Balancing (ELB)
What is Elastic Load Balancing?
Elastic Load Balancing (ELB) automatically distributes incoming application traffic across multiple targets (EC2, containers, Lambda) in one or more Availability Zones, ensuring high availability, fault tolerance, and performance.
It acts as the βtraffic copβ in your cloud architecture, ensuring no single server bears too much load.
Types of Load Balancers
AWS provides three main types of ELBs. Each is tailored to different types of applications:
Load Balancer | Description |
---|---|
Application Load Balancer (ALB) | Layer 7, HTTP/HTTPS, supports routing by path/host |
Network Load Balancer (NLB) | Layer 4, TCP/UDP, ultra-low latency & high throughput |
Gateway Load Balancer (GWLB) | Designed for third-party virtual appliances like firewalls |
βοΈ Key Features of ELB
- Health Checks: Automatically routes traffic only to healthy targets.
- SSL Termination: Offload SSL processing at the load balancer.
- Sticky Sessions: Maintain user sessions with a specific backend.
- Path-Based Routing: Route
/api
to one service and/static
to another (ALB). - WebSocket Support: ALB supports WebSocket protocols for real-time apps.
- IPv6 Support, WAF Integration, and Cross-Zone Load Balancing.
π οΈ How to Create an Application Load Balancer (ALB)
Using AWS Console:
- Open EC2 β Load Balancers β Create Load Balancer β Select ALB
- Define name, scheme (internet-facing), and VPC/subnets
- Choose Security Groups
- Add Listeners (e.g., HTTP/HTTPS)
- Configure Target Groups:
- Target Type: Instance, IP, Lambda
- Health checks path:
/health
or/
- Register Targets (EC2s)
- Review and Create
Using AWS CLI:
aws elbv2 create-load-balancer \
--name my-alb \
--subnets subnet-aaa subnet-bbb \
--security-groups sg-12345678 \
--scheme internet-facing \
--type application
Real Use Case Scenarios for ELB
Industry | Use Case |
---|---|
E-Commerce | Distribute traffic to frontend, API, payment gateways |
SaaS Applications | Microservice architecture routing with ALB |
Media & Gaming | Ultra-low latency using NLB |
Security Platforms | Use GWLB for inspecting all inbound traffic |
Best Practices for ELB
- Enable Access Logs for monitoring and audit.
- Use SSL/TLS termination to offload decryption from backend servers.
- Always deploy across multiple AZs for high availability.
- Protect with AWS WAF for web attack mitigation.
- Use ALB with ECS/EKS for containerized environments.
Part 2: Auto Scaling (ASG)
π What is Auto Scaling?
Auto Scaling allows AWS to automatically add (scale out) or remove (scale in) compute resources (like EC2 instances) based on real-time demand, saving costs while ensuring consistent performance.
Auto Scaling involves:
- Auto Scaling Group (ASG)
- Launch Template or Launch Configuration
- Scaling Policies
Key Components of Auto Scaling
Component | Description |
---|---|
Launch Template | Specifies the EC2 config (AMI, instance type, key pair, etc.) |
Auto Scaling Group | Logical group of EC2s managed together |
Scaling Policies | Rules to scale based on metrics (CPU, memory, request count) |
Warm Pools | Pre-initialized EC2s for faster scaling |
Scheduled Scaling | Scale based on time/date patterns |
Predictive Scaling | Uses machine learning to predict load trends |
How to Configure an Auto Scaling Group
Step-by-Step (AWS Console):
- Go to EC2 β Auto Scaling Groups β Create ASG
- Choose or create a Launch Template
- Set Group Name, VPC, and Subnets
- Choose Load Balancer (optional but recommended)
- Set:
- Desired Capacity (e.g., 2)
- Minimum Instances (e.g., 1)
- Maximum Instances (e.g., 5)
- Add Scaling Policies:
- Target Tracking (e.g., maintain CPU at 60%)
- Step Scaling (scale by count or percentage)
- Scheduled Scaling (e.g., increase at 9 AM)
Example CLI for Auto Scaling
β Create Launch Template:
aws ec2 create-launch-template \
--launch-template-name my-template \
--version-description "v1" \
--launch-template-data file://template-data.json
β Create Auto Scaling Group:
aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name my-asg \
--launch-template "LaunchTemplateName=my-template,Version=1" \
--min-size 1 --max-size 5 --desired-capacity 2 \
--vpc-zone-identifier "subnet-aaa,subnet-bbb"
Real-World Examples of Auto Scaling
Use Case | Description |
---|---|
Traffic Spikes on E-Commerce Website | Add EC2s automatically during sale hours |
SaaS with Variable Workload | Scale EC2s based on CPU usage or queue size |
24/7 Applications | Maintain minimum capacity + rapid scale-out |
Game Servers | Add capacity only during peak playing hours |
π Security Considerations for ELB & ASG
- Place EC2s in private subnets, only ALB in public
- Use IAM roles for EC2s for minimal access
- Configure Security Groups: ELB β EC2s only on required ports
- Regularly rotate AMIs and patch instances
- Use Auto Recovery feature for failed instances
Monitoring & Logging
Tool | What It Monitors |
---|---|
CloudWatch | Metrics (CPU, Network, Latency) |
CloudTrail | API usage for ELB & ASG |
ELB Access Logs | All incoming HTTP/HTTPS requests |
Auto Scaling Events | Scaling activity and reasons |
Use CloudWatch Alarms to trigger scale-out or scale-in policies.
π ELB + ASG Architecture Diagram (Textual)
User
β
[Route 53 - DNS]
β
[Application Load Balancer]
β
[Auto Scaling Group]
β³ EC2 Instance 1
β³ EC2 Instance 2
β³ EC2 Instance (scaled dynamically)
β
[Database - RDS/DynamoDB]
β This pattern ensures resilience, cost optimization, and scalability.
Summary
Feature | Load Balancing | Auto Scaling |
---|---|---|
Purpose | Distribute traffic | Dynamically adjust EC2 count |
Types | ALB, NLB, GWLB | Target tracking, step, scheduled |
Benefits | High availability, SSL offload | Cost-efficient scaling, redundancy |
Monitoring | Access logs, CloudWatch, WAF | CloudWatch, scaling activity logs |
Real-World Fit | Web apps, APIs, microservices | E-commerce, SaaS, event-driven apps |
π‘ Explore More AWS Tools & Resources
Educational AI Tutor
Get instant AWS-related answers and explanations using AI.
Interview Question Generator
Generate AWS interview questions for practice and preparation.
AWS Practice Quiz
Test your AWS knowledge with timed quizzes and scoring.
AWS Interview Questions
Browse frequently asked AWS interview questions with answers.