Elastic Load Balancing (ELB)
Elastic Load Balancing 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 its registered targets and routes traffic only to the healthy targets.
Types of Load Balancers
- Application Load Balancer (ALB)
- Layer 7 (HTTP/HTTPS).
- Routing based on content (Path-based, Host-based, Query string, Headers).
- Best for Microservices and Container-based applications (Docker/ECS).
- Supports WebSockets and HTTP/2.
- Network Load Balancer (NLB)
- Layer 4 (TCP/UDP/TLS).
- Ultra-high performance (Millions of requests/sec).
- Extremely low latency.
- Preserves Source IP.
- Static IP / Elastic IP support.
- Gateway Load Balancer (GLB)
- Layer 3 (Network/IP).
- Used for deploying third-party virtual appliances (Firewalls, IDS/IPS, Deep Packet Inspection).
- Operates on port 6081 (GENEVE protocol).
- Classic Load Balancer (CLB)
- Legacy (Layer 4 & 7).
- Avoid using unless you have EC2-Classic instances.
Key Features
- Health Checks: Periodically checks the status of registered targets. If a target fails, ELB stops sending traffic to it.
- Cross-Zone Load Balancing: Distributes traffic evenly across all registered instances in all enabled Availability Zones.
- ALB: Enabled by default. No charge.
- NLB: Disabled by default. Charges apply for inter-AZ data.
- Sticky Sessions (Session Affinity): Binds a user's session to a specific instance. (Cookies). Supported by ALB and CLB.
- SSL Offloading: The Load Balancer terminates the SSL connection, decrypting requests before sending them to targets.
Exam Tips
- Application (HTTP/S) or Web Sockets? -> Choose ALB.
- Extreme Performance or Static IP? -> Choose NLB.
- 3rd Party Firewall/Appliance? -> Choose GLB.
- 504 Gateway Timeout Error: The application (target) is unresponsive, not the load balancer.
- X-Forwarded-For: How to get the Client's real Key IP address when behind an ALB.
Common Use Cases
- Hoch Availability: Fault tolerance by distributing traffic.
- Automatic Scaling: ELB handles the traffic distribution as Auto Scaling adds/removes instances.
- Security: Hide backend instances behind the ELB (Private Subnet).