> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Elastic Load Balancing

> Overview of AWS Elastic Load Balancing covering ALB and NLB features, listeners, target groups, routing rules, health checks, cross zone balancing, and integrations for scalable high availability

In this lesson we'll cover Elastic Load Balancers (ELB) and why they are essential for scaling, availability, and protecting web applications on AWS. You'll learn core ELB concepts, differences between load balancer types, routing options provided by Application Load Balancers (ALBs), and how Network Load Balancers (NLBs) operate at high scale.

## Why use a load balancer?

Consider a website hosted on a single [EC2](https://learn.kodekloud.com/user/courses/amazon-elastic-compute-cloud-ec2) instance. Initially this may be fine, but as traffic grows a single server becomes a bottleneck. Two common scaling approaches:

* Vertical scaling — increase the instance size (CPU, RAM).
* Horizontal scaling — add more instances and distribute traffic across them.

Horizontal scaling requires a single entry point that can route requests across multiple backend instances. If the domain points to one EC2 IP, adding more instances won't help because traffic still targets that one IP. A load balancer becomes that single entry point and distributes requests according to configurable rules.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/voEwdRiXa9hDn_dx/images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-elb-t2-large-ec2-load-balancer.jpg?fit=max&auto=format&n=voEwdRiXa9hDn_dx&q=85&s=2b37679631ec97d0a8fc98cf5ac7adec" alt="A slide titled &#x22;Why Do We Need Load Balancer?&#x22; showing an AWS architecture diagram with three t2.large EC2 instances (with IPs) behind a load balancer that forwards traffic to a website (www.mywebsite.com) and users via an ELB endpoint." width="1920" height="1080" data-path="images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-elb-t2-large-ec2-load-balancer.jpg" />
</Frame>

Clients interact only with the load balancer; the load balancer forwards requests to backend targets (EC2, IPs, Lambda, or containers) based on the configured listeners and target groups.

## Core ELB concepts: Listeners and Target Groups

Two primary configuration elements used by AWS load balancers:

* Listener — a process on the load balancer that checks for connection requests on a specific protocol and port. ALB and NLB listeners can include rules that define how matching traffic is routed and what actions to take.
* Target group — a logical grouping of endpoints (EC2 instances, IP addresses, Lambda functions, or other load balancers) that receive traffic forwarded by the load balancer. Each target group has health check settings and a protocol/port configuration.

For example, create an HTTP (port 80) listener and forward incoming requests to a target group of EC2 instances listening on port 80. A separate HTTPS (port 443) listener can forward to a different target group.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/voEwdRiXa9hDn_dx/images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-load-balancer-https-target-groups.jpg?fit=max&auto=format&n=voEwdRiXa9hDn_dx&q=85&s=73549f6fc89cfa47987891fa95a469bb" alt="A diagram showing how an AWS load balancer routes HTTPS (port 443) traffic from a user to target groups/EC2 instances across multiple public subnets. The user visits https://www.mywebsite.com which is forwarded through the load balancer to backend servers." width="1920" height="1080" data-path="images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-load-balancer-https-target-groups.jpg" />
</Frame>

## Target group resources and supported protocols

Target groups support multiple target types and protocols:

| Target type | Use case |
| - | - |
| EC2 instances | Classic targets for VM-backed workloads |
| IP addresses | On-prem or cross-VPC targets reachable by IP |
| AWS Lambda functions | ALB integration for serverless handlers |
| Application Load Balancer | Chaining between load balancers or advanced architectures |

Supported protocols: TCP, UDP, TLS, HTTP, HTTPS. Target groups can forward to any port and support HTTP/1.1, HTTP/2, and gRPC. Health checks run periodically (HTTP/HTTPS or TCP) to determine target availability.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/voEwdRiXa9hDn_dx/images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/target-group-characteristics-health-http-https.jpg?fit=max&auto=format&n=voEwdRiXa9hDn_dx&q=85&s=a8f4f21d1cd59e122238ce85faabf1dd" alt="A slide titled &#x22;Target Group Characteristics&#x22; showing target types (Instances, IP Address, Lambda, Application Load Balancer) and icons, alongside boxes listing supported protocols, port range and protocol versions. A separate green box notes health checks use HTTP and HTTPS." width="1920" height="1080" data-path="images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/target-group-characteristics-health-http-https.jpg" />
</Frame>

## Health checks

Load balancer nodes continuously perform health checks on registered targets using configured intervals and thresholds. When a target fails health checks it is removed from routing until it passes health checks again. Health checks apply to instance and IP targets; Lambda targets are invoked and monitored differently by the ALB integration.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/voEwdRiXa9hDn_dx/images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-load-balancer-health-check-ec2.jpg?fit=max&auto=format&n=voEwdRiXa9hDn_dx&q=85&s=2b606e8f407e5550fd604fcb34d319cf" alt="An AWS architecture diagram titled &#x22;Load Balancer Health Check&#x22; showing a load balancer receiving client requests and routing to EC2 instances across multiple public subnets. Some instances are marked unhealthy with heartbeat lines and red Xs indicating failed health checks." width="1920" height="1080" data-path="images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-load-balancer-health-check-ec2.jpg" />
</Frame>

## Public vs Private load balancers

* Public (internet-facing) load balancer — accessible from the internet; suitable for public web apps and APIs.
* Private (internal) load balancer — accessible only from within the VPC; suitable for internal services, microservices, and internal APIs.

Private load balancers provide an additional security boundary since they are not reachable from the internet.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/voEwdRiXa9hDn_dx/images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-public-private-load-balancer-diagram.jpg?fit=max&auto=format&n=voEwdRiXa9hDn_dx&q=85&s=1f05b38602284d3ff09749b7fe4a0e1d" alt="A diagram titled &#x22;Public and Private Load Balancer&#x22; showing an AWS cloud architecture with public and private subnets connected to public and private load balancers. Traffic flows from users to a website (www.mywebsite.com) through the public LB into the subnets." width="1920" height="1080" data-path="images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-public-private-load-balancer-diagram.jpg" />
</Frame>

## Cross-zone load balancing

When you create a load balancer you choose subnets in specific Availability Zones (AZs); AWS deploys load balancer nodes into those subnets. Cross-zone load balancing affects how nodes forward traffic across AZs:

* ALB — automatically distributes traffic evenly across all registered targets in enabled AZs (no explicit toggle required).
* NLB — cross-zone load balancing is optional. When enabled, nodes can forward traffic to targets in any AZ; when disabled, a node only forwards to targets in its own AZ (which can cause uneven utilization).

Example: Cross-zone load balancing ON distributes requests across all targets in every AZ, improving distribution and avoiding hotspots.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/voEwdRiXa9hDn_dx/images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-cross-zone-load-balancing-diagram.jpg?fit=max&auto=format&n=voEwdRiXa9hDn_dx&q=85&s=273a58736163fcf2743a2ff4a5e4b336" alt="A network diagram illustrating AWS cross-zone load balancing: multiple public subnets with instances send/receive traffic via a central load balancer, with dotted arrows showing distribution across availability zones. On the right a user and Route 53 are shown, and the diagram indicates Cross-Zone Load Balancing is On." width="1920" height="1080" data-path="images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-cross-zone-load-balancing-diagram.jpg" />
</Frame>

## AWS load balancer types

AWS provides several load balancer types for different use cases. The two primary ones are:

| Load balancer | OSI layer | Typical protocols | Best for |
| - | - | - | - |
| Application Load Balancer (ALB) | Layer 7 (Application) | HTTP, HTTPS (HTTP/1.1, HTTP/2, gRPC) | Web apps, microservices, host/path-based routing, advanced request-level routing |
| Network Load Balancer (NLB) | Layer 4 (Transport) | TCP, UDP, TLS | High throughput, ultra-low latency, static IPs, non-HTTP workloads |

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/voEwdRiXa9hDn_dx/images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-lb-types-alb-nlb.jpg?fit=max&auto=format&n=voEwdRiXa9hDn_dx&q=85&s=e19c411a01f1d315caa68c122dac17b5" alt="A slide titled &#x22;Types of LB Supported by AWS&#x22; showing the OSI layers and two highlighted options: Application Load Balancer (ALB) at Layer 7 and Network Load Balancer (NLB) at Layer 4. The slide notes ALB supports HTTP/HTTPS and advanced routing, while NLB supports TCP/UDP/TLS, millions of requests per second, and static IPs per AZ." width="1920" height="1080" data-path="images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/aws-lb-types-alb-nlb.jpg" />
</Frame>

### How Network Load Balancer (NLB) works

* AWS creates a network interface in each AZ where the NLB is enabled; each interface provides a static IP for that AZ.
* For internet-facing NLBs you can associate Elastic IPs per subnet.
* NLBs operate at Layer 4: listeners match on ports (e.g., 80, 443, 8080) and forward based on port and protocol rather than HTTP content.
* NLBs can forward to IP-based targets outside the VPC (e.g., on-premises data center).

Listeners on an NLB match ports and forward traffic to the appropriate target group (instances, IPs, or ALBs).

## Application Load Balancer (ALB) features and routing rules

ALBs are HTTP-aware and allow powerful request-level routing. ALB rules can match on one or more of the following conditions:

* Host header (domain)
* URL path
* HTTP request method (GET, POST, PATCH, DELETE, etc.)
* Source IP (CIDR ranges)
* Specific HTTP headers
* Query string parameters

Rules are evaluated in priority order; the first match wins. If no rule matches, the default rule forwards to the default target group.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/voEwdRiXa9hDn_dx/images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/alb-listener-rules-conditions-actions.jpg?fit=max&auto=format&n=voEwdRiXa9hDn_dx&q=85&s=7fa2e7f33ca274dca9d5dda684f1be0c" alt="A diagram titled &#x22;Feature of ALB&#x22; showing an AWS Cloud box with a Listener (port 80) and rule blocks for Host Header, Path, HTTP Request Method, Source IP, HTTP Header, and Query String. Icons on the right depict actions such as Forward, Redirect, and Fixed Response." width="1920" height="1080" data-path="images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/alb-listener-rules-conditions-actions.jpg" />
</Frame>

### Host header routing

Route traffic for different hostnames to different target groups. Example: `blog.mywebsite.com` -> Blog target group; all other traffic -> Default target group.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/voEwdRiXa9hDn_dx/images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/alb-listener80-hostheader-blog-default.jpg?fit=max&auto=format&n=voEwdRiXa9hDn_dx&q=85&s=a5b1ba81b625cbbcb589aee7e0ca3753" alt="A diagram of an AWS Application Load Balancer listener (port 80) using host header rules. Requests for blog.mywebsite.com are routed to the &#x22;Blog&#x22; target group, while other traffic is forwarded to the default target group." width="1920" height="1080" data-path="images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/alb-listener80-hostheader-blog-default.jpg" />
</Frame>

### Path-based routing

Match on URL paths to forward traffic to different backends.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/voEwdRiXa9hDn_dx/images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/alb-listener-80-blog-default-targets.jpg?fit=max&auto=format&n=voEwdRiXa9hDn_dx&q=85&s=46142203ae3cfc266de8c458cdccf24c" alt="A diagram of an AWS Application Load Balancer showing a listener on port 80 with a path rule for &#x22;/blog&#x22; forwarded to a Blog target group and a default rule forwarded to a Default target group. It maps requests from mywebsite.com/blog and mywebsite.com to their respective target groups." width="1920" height="1080" data-path="images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/alb-listener-80-blog-default-targets.jpg" />
</Frame>

### Method-based routing

Route based on HTTP methods. For example, POST might go to a write-optimized target group while GET goes to a read-optimized group.

Example curl commands to test method- and header-based routing:

```bash theme={null}
# POST with JSON body and content-type (matches a rule for POST)
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://mywebsite.com/api

# Header-based routing examples
curl -H "x-environment: staging" https://mywebsite.com/api
curl -H "x-client: premium" https://mywebsite.com/api
curl -H "x-client: medium" https://mywebsite.com/api

# Default (no special headers or method)
curl https://mywebsite.com/api
```

### Source IP, header, and query-string routing

Match client IP ranges (CIDR) to route corporate traffic differently from public traffic:

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/voEwdRiXa9hDn_dx/images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/alb-listener80-sourceip-20216614080-office-default.jpg?fit=max&auto=format&n=voEwdRiXa9hDn_dx&q=85&s=d69e32c11ef03c1b8801a882aa6cdfa8" alt="A diagram of an AWS Application Load Balancer showing a listener on port 80 with a source-IP rule that matches 202.166.140.80/32 and forwards that traffic to an &#x22;Office&#x22; target group. The default rule forwards all other traffic (0.0.0.0/0) to the Default target group." width="1920" height="1080" data-path="images/AWS-Solutions-Architect-Associate-Certification/Services-Application-Integration/Elastic-Load-Balancing/alb-listener80-sourceip-20216614080-office-default.jpg" />
</Frame>

Header-based example:

```bash theme={null}
curl -H "x-environment: staging" https://mywebsite.com/api
```

Query-string example:

```bash theme={null}
curl "https://mywebsite.com/api?category=books"
```

### Mixing conditions

Combine host, path, header, method, source IP, and query string conditions to build precise routing logic. Rules are processed by priority; the first matching rule applies. If no rule matches, the default target group handles the request.

Example: route by `X-Client` header to different instance types:

```bash theme={null}
# Premium clients
curl -H "x-client: premium" https://mywebsite.com/api

# Medium clients
curl -H "x-client: medium" https://mywebsite.com/api

# Default
curl https://mywebsite.com/api
```

## Integrations and ecosystem

Elastic Load Balancing integrates with many AWS services:

* [EC2](https://learn.kodekloud.com/user/courses/amazon-elastic-compute-cloud-ec2) & Auto Scaling — instances register/deregister automatically as group scales.
* [Amazon ECS](https://learn.kodekloud.com/user/courses/amazon-elastic-container-service-aws-ecs) — ALB/NLB route to container tasks.
* [AWS Lambda](https://learn.kodekloud.com/user/courses/aws-lambda) — ALB can invoke Lambda functions as targets.
* [AWS WAF](https://aws.amazon.com/waf/) — attach a Web Application Firewall to protect apps from common exploits.
* [Amazon Route 53](https://aws.amazon.com/route53/) — use DNS to point custom domains to the load balancer endpoint.
* [AWS CloudWatch](https://learn.kodekloud.com/user/courses/aws-cloudwatch) & [CloudTrail](https://aws.amazon.com/cloudtrail/) — monitoring and logging for metrics and audit trails.

Auto Scaling groups typically register instances with a load balancer so new instances immediately receive traffic and terminated instances are deregistered automatically.

<Callout icon="lightbulb" color="#1CB2FE">
  Plan listener rules and target groups to map traffic patterns (host, path, headers, methods) to the correct backends. Use health checks to ensure only healthy targets receive traffic and leverage ALB rules to keep routing logic efficient and maintainable.
</Callout>

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/aws-solutions-architect-associate-certification/module/2a5c60f6-2d46-4dfe-a2e2-66c7eae45a70/lesson/a74f8759-2290-4aca-bd86-3e21a1269c72" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/aws-solutions-architect-associate-certification/module/2a5c60f6-2d46-4dfe-a2e2-66c7eae45a70/lesson/d0d84afc-043a-4466-a7be-0e633c9122f2" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.