Elastic Load Balancing (ELB) in AWS
Elastic Load Balancing (ELB) is an AWS service that automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers, IP addresses, and Lambda functions. It helps improve the availability and fault tolerance of your applications.
Types of Load Balancers
AWS offers three main types of load balancers, each designed for specific use cases:
Application Load Balancer (ALB)
- Layer: Operates at the application layer (Layer 7 of the OSI model).
- Features: Supports content-based routing (routing requests based on URL path, host header, or query string), host-based routing, and path-based routing. It's ideal for microservices and container-based applications.
- Protocols: Supports HTTP, HTTPS, and gRPC.
- Use Cases: Routing traffic to different services or containers based on the request content, load balancing HTTP/HTTPS traffic for web applications.
Network Load Balancer (NLB)
- Layer: Operates at the connection layer (Layer 4 of the OSI model).
- Features: Handles millions of requests per second with ultra-low latency. It's designed for extreme performance and static IP addresses.
- Protocols: Supports TCP, UDP, and TLS.
- Use Cases: Load balancing high-performance applications, gaming services, or any application requiring static IP addresses and high throughput.
Gateway Load Balancer (GLB)
- Layer: Operates at Layer 3 (network layer) and Layer 4 (transport layer).
- Features: Simplifies the deployment, scaling, and management of third-party virtual appliances (e.g., firewalls, intrusion detection systems) by acting as a transparent network gateway.
- Protocols: Supports IP protocol.
- Use Cases: Inserting virtual appliances into a network path, centralizing security and network inspection.
Key Concepts
- Listeners: A process that checks for connection requests, using the protocol and port that you configure. Listeners can be configured for different protocols (HTTP, HTTPS, TCP, UDP, TLS) and ports.
- Target Groups: A logical grouping of targets (e.g., EC2 instances, IP addresses) that the load balancer routes requests to. Each target group can have its own health checks and routing rules.
- Health Checks: The load balancer periodically sends requests to registered targets to check their health. If a target fails health checks, the load balancer stops sending traffic to it until it becomes healthy again.
- Routing Rules: For ALBs, you can define rules that determine how requests are routed to different target groups based on various conditions (e.g., host header, URL path).
- Cross-Zone Load Balancing: Distributes traffic evenly across all registered instances in all enabled Availability Zones, regardless of the number of instances in each zone. This helps improve fault tolerance.
- Sticky Sessions (Session Affinity): Ensures that requests from the same client are always routed to the same target. This is useful for applications that maintain session state on the server.
- SSL/TLS Termination: Load balancers can handle SSL/TLS decryption and encryption, offloading this task from your backend instances. This improves performance and simplifies certificate management.
Benefits of ELB
- High Availability: Distributes traffic across multiple Availability Zones, ensuring that your application remains available even if one zone experiences an outage.
- Scalability: Automatically scales its capacity to handle changes in application traffic, without manual intervention.
- Fault Tolerance: Automatically detects unhealthy targets and routes traffic only to healthy ones, improving the reliability of your application.
- Security: Integrates with AWS WAF (Web Application Firewall) for ALBs to protect against common web exploits, and supports SSL/TLS termination for encrypted communication.
- Cost-Effective: You pay only for the load balancer capacity you use.
How ELB Works
- Client Request: A client sends a request to the DNS name of your load balancer.
- DNS Resolution: The DNS resolves the load balancer's DNS name to its IP addresses.
- Traffic Distribution: The load balancer receives the request and, based on its configuration (listeners, rules, target groups), routes the request to a healthy target.
- Target Response: The target processes the request and sends a response back to the client through the load balancer.
