Skip to main content
In this lesson we’ll explore AWS Elastic Load Balancing (ELB): what it does, why it’s essential for scalable web applications, and how to choose and configure the right load balancer for your use case. You’ll learn key concepts (listeners, target groups, health checks), differences between public and private load balancers, cross‑zone behavior, and the main AWS load balancer types (ALB and NLB) with concrete routing examples. Why do we need load balancers? If your site (for example, mywebsite.com) runs on a single EC2 instance, growth in traffic will eventually overwhelm that instance. There are two primary scaling approaches:
  • Vertical scaling — increase instance size (CPU, memory).
  • Horizontal scaling — add more instances and distribute traffic among them.
Horizontal scaling requires a single entry point that can route requests to multiple backend instances. A load balancer gives you that single endpoint (domain or IP) and forwards incoming requests to a pool of targets so traffic is distributed and availability is improved.
A diagram titled "Why Do We Need Load Balancer?" showing an AWS Elastic Load Balancer routing user traffic (elb.aws.amazon.com → www.mywebsite.com) to three EC2 t2.large instances inside the AWS Cloud. The instances are listed with IPs (121.10.30.30–32) and arrows indicating load-balanced traffic flow.
The customer interacts only with the load balancer; the load balancer forwards requests to the appropriate backend instances. AWS ELB is designed to be scalable and fault-tolerant and can distribute traffic across Availability Zones. Core ELB concepts: listeners and target groups Two foundational ELB concepts are:
  • Listener — defines the protocol and port on the load balancer that receives incoming connections (for example, HTTP on 80 or HTTPS on 443). A listener contains rules to decide how to route requests.
  • Target group — a logical set of targets (EC2 instances, IP addresses, Lambda functions, or another load balancer). The load balancer forwards matched requests to targets in a target group.
You can have multiple listeners on one load balancer (e.g., HTTP and HTTPS). Each listener can route to different target groups according to rules.
A diagram showing how an AWS load balancer routes HTTPS (port 443) traffic from a user accessing www.mywebsite.com to target groups of web servers in multiple public subnets. The load balancer component sits between the internet-facing site icon and the backend instances.
Target groups — capabilities and practical details Target groups are flexible and power ELB routing. Key capabilities: Health checks are run by the target group. If a target fails its health check, the load balancer stops routing traffic to it until it passes again.
A diagram titled "Load Balancer Health Check" showing an AWS cloud with multiple public subnets containing server instances and a load balancer on the right handling a client request. Some instances are marked with red Xs and dashed heartbeat lines to indicate failed health checks.
Public vs private load balancers
  • Public (Internet-facing) load balancer — accepts traffic from the internet; suitable for public websites and APIs.
  • Private (internal) load balancer — accessible only within a VPC; suitable for internal services and microservices that shouldn’t be internet-exposed.
Common pattern: a public load balancer in front of web servers (public subnets) and a private load balancer internal to the VPC to route between internal services.
A diagram of an AWS architecture showing public and private load balancers routing traffic between multiple public and private subnets to a website (www.mywebsite.com) and end users. Icons depict the AWS cloud boundary, subnets, load balancers, a website endpoint, and user group.
Cross‑zone load balancing When you create a load balancer, you choose subnets in specific Availability Zones and AWS deploys load balancer nodes in those AZs. Historically, each node forwarded only to targets in its own AZ. Cross‑zone load balancing enables nodes to forward traffic to targets in other AZs, which improves traffic distribution and reduces hotspots.
A diagram titled "What Is Cross‑Zone Load Balancing?" showing an AWS Cloud with three public subnets containing compute instances and a central load balancer distributing traffic across those subnets. On the right are a user icon and a Route 53 DNS icon indicating incoming requests.
Types of AWS load balancers (when to use which) Below is a quick comparison of the main AWS load balancers to help match features to workloads:
A slide showing "Types of LB Supported by AWS," comparing the Application Load Balancer (ALB) at the application layer and the Network Load Balancer (NLB) at the transport layer. It lists ALB features (HTTP/HTTPS, advanced routing) and NLB features (TCP/UDP/TLS, high throughput, static IP per AZ).
How the Network Load Balancer (NLB) works
  • NLB target groups support EC2 instances, IP addresses, and ALBs.
  • When you create an NLB, AWS creates a network interface for each enabled Availability Zone. Each load balancer node uses that interface and can be assigned a static IP.
  • For internet-facing NLBs, you can associate an Elastic IP per subnet/AZ.
  • NLB forwards at the transport layer (ports/protocols). You can route different incoming ports to different target groups (including targets outside the VPC via IP targets).
Example:
  • Port 8080 → forward to a corporate datacenter via an IP target group
  • Port 80 → forward to web instances in a target group
  • Port 443 → forward to another secure target group
NLB is ideal when you need extremely high throughput, static IPs, or to forward traffic to non‑HTTP endpoints.
A network architecture diagram titled "How Does NLB Work?" showing traffic flow between a corporate data center and an AWS Cloud setup with public subnets, compute instances, and a Network Load Balancer handling ports 8080, 80, and 443. The diagram uses arrows and icons to show routing between subnets, instances, and the load balancer.
Application Load Balancer (ALB) — Layer 7 routing features Because ALB understands HTTP, it supports rich, application-aware routing and request manipulation:
  • Rule conditions: host headers, URL paths, HTTP methods, headers, query strings, source IP.
  • Actions: forward to different target groups, HTTP redirects, response modification, path rewrites.
  • Protocol support: HTTP/1.1, HTTP/2, gRPC.
  • Useful for microservices — route each service behind its own target group and use routing rules to dispatch traffic.
Host-based routing example By default the ALB has a fallback (default) rule that forwards unmatched traffic to a default target group. You can add rules such as:
  • If host header == blog.mywebsite.com → forward to Blog target group
An AWS architecture diagram showing an Application Load Balancer (listener on port 80) using host header rules to route blog.mywebsite.com to a "Blog" target group and other requests to a default target group. Client requests (http://blog.mywebsite.com and http://mywebsite.com) are shown being forwarded accordingly.
Path‑based routing example You can route requests based on URL path. Example rule:
  • If path starts with /blog → forward to Blog target group
  • Else → forward to Default target group
Diagram of an AWS Application Load Balancer showing path-based routing. The listener on port 80 sends requests for /blog to a Blog target group and forwards all other traffic to a default target group (example URLs shown).
HTTP method-based routing ALB can match on HTTP method so you can separate traffic by operation type. Example: send POSTs to a different target group than GETs. Example curl for a POST request:
Header-based and query-string routing Match custom headers:
Match query string values:
Combining rules You can combine rule conditions to build complex routing logic. For example, detect a premium client header plus a path and send that traffic to a high-performance target group; medium clients go to a different group; all others use the default. Example requests to test rules:
A diagram of an AWS Application Load Balancer showing a listener on port 80 with a source-IP rule for 202.166.140.80/32 routed to an "Office" target group. The default rule forwards all other traffic (0.0.0.0/0) to a Default target group.
Integration with other AWS services ELB integrates directly with many AWS services to support modern architectures:
  • EC2 — register instances as targets.
  • ECS — register tasks (dynamic ports) with target groups.
  • AWS Lambda — ALB can forward requests to Lambda functions.
  • AWS WAF — place WAF in front of ALB to protect from web attacks.
  • Route 53 — map custom domains to load balancer endpoints using Alias/ALIAS records.
  • Auto Scaling — instances launched/terminated by Auto Scaling are automatically registered/deregistered with target groups.
When using Auto Scaling groups with a load balancer, instances are automatically registered and deregistered with the target group as they launch or terminate. This ensures traffic is only sent to healthy, in-service instances.
Further reading and references

Watch Video

Practice Lab