You already know what a load balancer is and when to use ALB or NLB. Now let's open the box and look at its three internal components: the listeners (what traffic it listens to), the rules (how it decides), and the Target Groups (which servers it sends to). Understanding these three pieces is understanding how a load balancer really works.

The journey of a request

When a user visits your website through the load balancer, their request goes through three stages:

User ──► [ LISTENER ] ──► [ RULES ] ──► [ TARGET GROUP ] ──► Server
         "I listen to     "I decide      "group of
          port 443"        where it goes"  servers"

Let's look at each piece.

  1. Listener: what traffic the load balancer listens to

A listener is an "open door" of the load balancer that listens on a specific port. For example:

  • A listener on port 80 listens to HTTP traffic.
  • A listener on port 443 listens to HTTPS (secure) traffic.
Load Balancer
 ├── Listener port 80  (HTTP)  → usually redirects to HTTPS
 └── Listener port 443 (HTTPS) → handles secure requests

Analogy: listeners are like the different phone lines of a company. One line for sales (port 80), another for support (port 443). Each one listens and, depending on who calls, forwards to the correct department.

A very common pattern: the listener on port 80 (HTTP) automatically redirects to 443 (HTTPS) to enforce secure connections.

  1. Target Group: the destination server group

A Target Group is a list of servers (EC2 instances, containers, Lambda functions...) that receive the traffic. The load balancer does not send requests to individual servers, but to a Target Group, which groups the destinations.

Target Group "web-servers"
 ├── Server 1  ✓ healthy
 ├── Server 2  ✓ healthy
 └── Server 3  ✗ not responding  ← the load balancer does NOT send traffic to it

Health checks: the magic of high availability

Here is one of the most important keys: each Target Group performs health checks. Periodically, the load balancer "asks" each server if it is okay (for example, by making a request to a URL like /health).

  • If the server responds correctly → it is "healthy", it receives traffic.
  • If it does not respond (it has crashed, is overloaded...) → it is marked "unhealthy" and the load balancer stops sending requests to it automatically, until it recovers.

This is what provides the high availability from subchapter 13.1. Thanks to health checks, if a server fails, users never reach it: the load balancer redirects them to healthy servers without anyone noticing the problem. Without health checks, the load balancer would keep sending people to a downed server.

  1. Rules: how the load balancer decides

Rules connect listeners with Target Groups. In an ALB (which is smart, layer 7), rules can look at the content of the request to decide which Target Group to send it to:

Listener 443 (HTTPS)
 ├── Rule: if the path is /api/*   → Target Group "api-servers"
 ├── Rule: if the path is /images/* → Target Group "static-servers"
 └── Default rule                  → Target Group "web-servers"

This is the smart routing we mentioned in subchapter 13.1: a single load balancer can distribute traffic to different groups of servers depending on the URL, domain, headers, etc.

How it all fits together: an example

Imagine an online store. The journey of a request to https://store.com/api/products:

  1. Listener on port 443 (HTTPS) receives the request.
  2. A rule sees that the path starts with /api/ → sends it to the Target Group api-servers.
  3. The Target Group api-servers has 3 servers; 2 are healthy. It sends the request to one of the healthy ones.
  4. That server responds, and the response returns to the user the same way.
User → Listener 443 → Rule (/api/*) → API Target Group → Healthy server

Summary table

Component What it does Analogy
Listener Listens on a port (80, 443...) Phone line
Rule Decides which Target Group to send to Receptionist who forwards
Target Group Group of destination servers, with health checks Department with its employees
Health check Checks if each server is healthy Roll call

What you should remember

  • A request goes through three stages: Listener (listens on a port) → Rules (decide the destination) → Target Group (servers that respond).
  • The listener listens on a port (80 for HTTP, 443 for HTTPS); it's common to redirect 80 → 443.
  • The Target Group groups the destination servers and performs health checks: if a server does not respond, it automatically stops receiving traffic. This is what provides high availability.
  • Rules (in the ALB) allow smart routing by path, host, or headers to different Target Groups.

In the next subchapter we will see the other half of the magic: how to create and delete servers automatically according to demand, with Auto Scaling Groups.

Cloud, AWS & Terraform — From Zero to Expert

Chapter 1 · What is cloud computing

Chapter 2 · The cloud market and major providers

Chapter 3 · Regions, availability zones and edge

Chapter 4 · Compute: EC2

Chapter 5 · Storage: S3

Chapter 6 · Networking: VPC

Chapter 7 · Identity and access: IAM

Chapter 8 · Managed databases

Chapter 9 · Why Infrastructure as Code

Chapter 10 · HCL: the Terraform language

Chapter 11 · Providers and state

Chapter 12 · Your first real infrastructure in Terraform

Chapter 13 · Load balancing and auto scaling

Chapter 14 · Serverless with Lambda

Chapter 15 · Messaging and events

Chapter 16 · Content delivery and DNS

Chapter 17 · Containers on AWS

Chapter 18 · Modules: reuse and composition

Chapter 19 · Workspaces and environment management

Chapter 20 · Remote backends and locking

Chapter 21 · Infrastructure testing

Chapter 22 · Terraform in CI/CD

Chapter 23 · Defense in depth

Chapter 24 · Observability: logs, metrics and traces

Chapter 25 · Cost optimization

Chapter 26 · High availability and disaster recovery

Chapter 27 · AWS Well-Architected Framework

Chapter 28 · Serverless architectures at scale

Chapter 29 · Data platforms on AWS

Chapter 30 · Multi-account and landing zones

Chapter 31 · Platform Engineering and Internal Developer Platform

Chapter 32 · Relevant AWS certifications

Chapter 33 · Projects to consolidate what you've learned

Chapter 34 · Resources and community

© Copyright 2024. All rights reserved