Understanding Load Balancing, Scalability, and High Availability
AWS Elastic Load Balancing (ELB) automatically distributes incoming application traffic across multiple targets, such as EC2 instances, containers, and IP addresses, in one or more Availability Zones. It monitors the health of registered targets and routes traffic only to healthy targets.
A process that checks for connection requests using the protocol and port you configure. Each load balancer needs at least one listener.
A collection of targets (EC2 instances, IP addresses, Lambda functions, etc.) that receive traffic from the load balancer.
Define how requests are routed to targets. Each rule consists of a priority, one or more actions, and one or more conditions.
Periodic tests to verify that targets are functioning as expected.
┌───────────────────────────────────────────────────────────────────────────────────────────────────┐
│ │
│ Internet │
│ │ │
└────────────────────────────────────────────┼──────────────────────────────────────────────────────┘
│
▼
┌───────────────────────────────────────────────────────────────────────────────────────────────────┐
│ │
│ Security Group │
│ │ │
└────────────────────────────────────────────┼──────────────────────────────────────────────────────┘
│
▼
┌───────────────────────────────────────────────────────────────────────────────────────────────────┐
│ │
│ Elastic Load Balancer │
│ │ │
│ │ │
│ ┌───────────────────────────┼───────────────────────────┐ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Listener 1 │ │ Listener 2 │ │ Listener 3 │ │
│ │ (HTTP:80) │ │ (HTTPS:443) │ │ (TCP:3306) │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Rules │ │ Rules │ │ Rules │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │Target Group1│ │Target Group2│ │Target Group3│ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │ │
└────────────────┼───────────────────────────┼───────────────────────────┼──────────────────────────┘
│ │ │
▼ ▼ ▼
┌────────────────────────────┐ ┌────────────────────────────┐ ┌────────────────────────────┐
│ │ │ │ │ │
│ EC2 Instances │ │ Containers │ │ Lambda Functions │
│ IP Addresses │ │ IP Addresses │ │ │
│ │ │ │ │ │
└────────────────────────────┘ └────────────────────────────┘ └────────────────────────────┘
| Aspect | Scalability | Availability |
|---|---|---|
| Primary Focus | Performance and capacity | Uptime and reliability |
| Measures | Throughput, response time | Uptime percentage, MTBF |
| Challenges | Resource limits, costs | Single points of failure |
| Solutions | Auto Scaling, larger instances | Redundancy, failover |
| ELB Features | Connection draining, auto scaling integration | Multi-AZ deployment, health checks |
$0.0225 per ALB-hour (or partial hour) + $0.008 per LCU-hour (or partial hour)
LCU = Load Balancer Capacity Unit, based on new connections, active connections, bandwidth, and rule evaluations
$0.0225 per NLB-hour (or partial hour) + $0.006 per LCU-hour (or partial hour)
NLB LCU based on new connections, active connections, and bandwidth
$0.0225 per GWLB-hour (or partial hour) + $0.008 per LCU-hour (or partial hour)
GWLB LCU based on new connections, active connections, and bandwidth
Note: Not recommended for new applications. Use ALB or NLB instead.
$0.025 per CLB-hour (or partial hour) + $0.008 per GB of data processed
| Feature | Application LB | Network LB | Gateway LB | Classic LB |
|---|---|---|---|---|
| OSI Layer | Layer 7 | Layer 4 | Layer 3/4 | Layer 4/7 |
| Protocol Support | HTTP, HTTPS | TCP, UDP, TLS | IP (GENEVE) | TCP, SSL/TLS, HTTP, HTTPS |
| Static IP | No | Yes | Yes | No |
| Connection Draining | Yes (Deregistration Delay) | Yes (Deregistration Delay) | Yes (Deregistration Delay) | Yes |
| Path-based Routing | Yes | No | No | No |
| WebSocket | Yes | Yes | No | No |
| HTTP/2 | Yes | No | No | No |
| Sticky Sessions | Yes (Application or Duration-based) | Yes (Source IP) | Yes (Flow Hash) | Yes (Duration-based) |
Security groups act as virtual firewalls for your load balancers and instances, controlling inbound and outbound traffic.
# Inbound Rules HTTP (80): 0.0.0.0/0 HTTPS (443): 0.0.0.0/0 # Outbound Rules All traffic: Target Security Group
# Inbound Rules HTTP (80): Load Balancer Security Group HTTPS (443): Load Balancer Security Group # Outbound Rules All traffic: 0.0.0.0/0
Load balancers can decrypt HTTPS traffic before sending it to targets, reducing the computational load on backend servers.
Predefined security policies that specify SSL protocols, ciphers, and server order preference.
Network Access Control Lists (NACLs) provide an additional layer of security at the subnet level.
# Inbound Rules 100: Allow HTTP (80) from 0.0.0.0/0 110: Allow HTTPS (443) from 0.0.0.0/0 120: Allow ephemeral ports (1024-65535) from 0.0.0.0/0 * Deny all other traffic # Outbound Rules 100: Allow HTTP (80) to 0.0.0.0/0 110: Allow HTTPS (443) to 0.0.0.0/0 120: Allow ephemeral ports (1024-65535) to 0.0.0.0/0 * Deny all other traffic
# Example: Upgrading instance type aws ec2 modify-instance-attribute \ --instance-id i-1234567890abcdef0 \ --instance-type t3.large
# Example: Registering targets with ALB aws elbv2 register-targets \ --target-group-arn arn:aws:elasticloadbalancing:... \ --targets Id=i-1234567890abcdef0 Id=i-0987654321fedcba0
Auto Scaling Groups (ASG) automatically adjust the number of EC2 instances based on demand.
# Create Auto Scaling Group with Load Balancer aws autoscaling create-auto-scaling-group \ --auto-scaling-group-name my-asg \ --launch-template LaunchTemplateId=lt-1234567890abcdef0,Version='$Latest' \ --min-size 2 \ --max-size 10 \ --desired-capacity 2 \ --target-group-arns arn:aws:elasticloadbalancing:... \ --health-check-type ELB \ --health-check-grace-period 300 \ --vpc-zone-identifier "subnet-1234567890abcdef0,subnet-0987654321fedcba0"
# Create ALB with multiple AZs aws elbv2 create-load-balancer \ --name my-load-balancer \ --subnets subnet-12345678 subnet-87654321 \ --security-groups sg-12345678 \ --scheme internet-facing
# Configure health checks aws elbv2 modify-target-group \ --target-group-arn arn:aws:elasticloadbalancing:... \ --health-check-protocol HTTP \ --health-check-port 80 \ --health-check-path /health \ --healthy-threshold-count 2 \ --unhealthy-threshold-count 2 \ --health-check-timeout-seconds 5 \ --health-check-interval-seconds 30
Each load balancer node distributes traffic only among the registered targets in its Availability Zone.
Zone A: LB Node → 5 targets (20% traffic per target) Zone B: LB Node → 2 targets (50% traffic per target) Zone C: LB Node → 3 targets (33% traffic per target)
Result: Uneven distribution across targets in different AZs
Each load balancer node distributes traffic evenly across all registered targets in all enabled Availability Zones.
Zone A: LB Node → All 10 targets (10% traffic per target) Zone B: LB Node → All 10 targets (10% traffic per target) Zone C: LB Node → All 10 targets (10% traffic per target)
Result: Even distribution across all targets regardless of AZ
# Create CloudWatch alarm for high latency aws cloudwatch put-metric-alarm \ --alarm-name HighLatencyAlarm \ --alarm-description "Alarm when latency exceeds threshold" \ --metric-name TargetResponseTime \ --namespace AWS/ApplicationELB \ --statistic Average \ --period 60 \ --threshold 1 \ --comparison-operator GreaterThanThreshold \ --dimensions Name=LoadBalancer,Value=app/my-load-balancer/50dc6c495c0c9188 \ --evaluation-periods 2 \ --alarm-actions arn:aws:sns:region:account-id:my-topic
Access logs capture detailed information about requests sent to your load balancer, stored in an S3 bucket.
# Enable access logs for ALB
aws elbv2 modify-load-balancer-attributes \
--load-balancer-arn arn:aws:elasticloadbalancing:... \
--attributes Key=access_logs.s3.enabled,Value=true \
Key=access_logs.s3.bucket,Value=my-access-logs-bucket \
Key=access_logs.s3.prefix,Value=my-app-logs
AWS X-Ray helps trace requests through your application, providing insights into performance bottlenecks.
To enable X-Ray tracing with ALB:
Create custom dashboards to monitor your load balancers and targets in one place.
# Create CloudWatch dashboard aws cloudwatch put-dashboard \ --dashboard-name "ELB-Monitoring" \ --dashboard-body file://elb-dashboard.json
Netflix uses AWS ELB extensively to handle millions of streaming requests globally.
Amazon's e-commerce platform uses sophisticated load balancing to handle peak shopping events like Prime Day.
Best for:
Best for:
Best for:
Best for: