Why Do We Need Load Balancers?
High availability depends on the effective distribution of network traffic across multiple active endpoints. Consider a scenario where your website, mywebsite.com, is hosted on a single EC2 instance (for example, a T2 Large instance). As traffic increases, vertical scaling (simply upsizing the instance) can lead to downtime and disruption during the switchover. In contrast, horizontal scaling—adding more instances—ensures continuous service; however, directly pointing your domain to a specific IP address makes it challenging to manage traffic coherently across multiple instances. A load balancer acts as an abstraction layer between the client and your servers. Users connect to the load balancer rather than directly to an instance (e.g., IP 121.10.30.30). The load balancer then dynamically directs requests to backend instances based on availability, ensuring uninterrupted service.
Elastic Load Balancer and Target Groups
AWS Elastic Load Balancer (ELB) works in tandem with EC2 instances by organizing them into target groups. It continuously monitors target health using configurable health checks. If an instance becomes unresponsive, it is automatically removed from the target group, ensuring that only healthy endpoints receive traffic.

Virtual Load Balancer Architecture and Cross-Zone Load Balancing
Although a load balancer appears as a single device, it is, in fact, an aggregation of several virtual devices distributed across multiple availability zones. This redundancy guarantees there is no single point of failure. When cross-zone load balancing is enabled, the load balancer can distribute traffic amongst all available instances across zones. If disabled, traffic is limited to instances within a particular availability zone.
Types of AWS Load Balancers
AWS provides three primary types of load balancers, each designed for different use cases:-
Application Load Balancer (ALB):
- Operates at Layer 7 (the application layer).
- Supports advanced routing features such as path-based routing, host header routing, HTTP methods, source IP filtering, and query string rules.
- Ideal for HTTP/HTTPS traffic.
With ALB, you can route requests based on paths (e.g., /blog, /mobile), headers, query strings, or even HTTP methods. For example, a request containing the header “x-environment: staging” or a query string like “?category=books” can be directed to a dedicated target group:Multiple prioritized rules can be configured so that different traffic patterns are routed to appropriate resources, with a default rule handling unmatched requests.

- Network Load Balancer (NLB):
- Operates at Layer 4 (transport layer).
- Supports TCP, UDP, and TLS protocols.
- Ideal for scenarios that require extremely high performance (scaling to millions of connections per second).
- Provides static IP addresses, simplifying IP whitelisting and integration with legacy systems.
- Capable of forwarding traffic to targets outside a VPC (e.g., a corporate data center) via VPN or Direct Connect.

-
Security Load Balancer:
- Utilizes the Geneve protocol for traffic interception and filtering.
- Primarily used for specialized security purposes.
- While it does distribute traffic, its functionality is distinct from that of ALB and NLB.

Application Load Balancer (ALB) Detailed Configuration
When configuring an ALB, you define one or more listeners to manage incoming traffic. A listener on port 80 might include several rules:-
Host Header Rule:
Routes traffic based on the domain name (e.g., blog.mywebsite.com). -
Path Rule:
Routes traffic based on the URI path (e.g., /blog, /mobile). -
HTTP Method Rule:
Routes traffic based on HTTP methods (GET, POST, etc.). For example, you can direct POST requests to a designated API target group: -
Source IP or Header Rule:
Routes traffic based on the client’s IP address or specific header values (e.g., “x-environment: staging”).

Integration with AWS Services
Elastic Load Balancing seamlessly integrates with various AWS services:- Amazon EC2: Directly routes traffic to EC2 instances.
- Amazon ECS: Supports containerized applications.
- AWS Lambda: ALBs can trigger Lambda functions as backend services.
- AWS WAF: A Web Application Firewall can be positioned in front of a load balancer to filter malicious traffic.
- Amazon Route 53: The load balancer’s DNS name is usually managed through Route 53.
- Auto Scaling: Works in conjunction with auto scaling groups to adjust to changing loads.

Summary
- A load balancer acts as an abstraction layer, routing client requests to healthy backend instances distributed across multiple Availability Zones.
- AWS provides three main types of load balancers:
- Application Load Balancer (ALB): Offers advanced Layer 7 routing suitable for HTTP/HTTPS traffic.
- Network Load Balancer (NLB): Provides high-performance Layer 4 load balancing for TCP, UDP, and TLS protocols.
- Security Load Balancer: Designed for specialized security requirements using the Geneve protocol.
- Correct configuration of listeners, rules, and target groups is pivotal for ensuring efficient traffic distribution, high availability, and fault tolerance.
Remember that each load balancer type has its specific use cases. Choose the one that best fits your application’s requirements and infrastructure.