Elastic Load Balancing
Application, Network and Gateway Load Balancers: listeners, rules, target groups, health checks, draining, cross-zone behaviour and reading 5xx errors.
Launch templates and Auto Scaling groupsSecurity groups and network ACLs
Elastic Load Balancing
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A load balancer gives clients one stable name and sends each connection or request to a healthy target in one of several zones.
- Use an Application Load Balancer for HTTP, a Network Load Balancer for TCP, UDP, TLS or static addresses, and a Gateway Load Balancer to insert network appliances.
- A listener accepts traffic, rules decide where it goes, and a target group holds the targets and their health check.
- Deregistration delay lets in-flight requests finish. It defaults to 300 seconds.
- If every target in a group is unhealthy, an Application Load Balancer fails open and sends traffic to all of them.
- Cross-zone balancing is on for Application Load Balancers and off by default for Network Load Balancers.
One door, many rooms
You now have a fleet whose members appear and disappear. Clients cannot keep a list of them. They need one address that stays put while everything behind it changes, and something that stops sending work to the broken ones.
That is a load balancer, and like a good receptionist it knows who is at their desk today. The general ideas are in layer 4 versus layer 7 and balancing algorithms.
Three kinds
| Application (ALB) | Network (NLB) | Gateway (GWLB) | |
|---|---|---|---|
| Works on | HTTP requests (layer 7) | connections (layer 4) | IP packets (layer 3) |
| Protocols | HTTP, HTTPS, including gRPC and WebSocket | TCP, UDP, TLS, QUIC | all IP |
| Routes by | host, path, headers and more | port | flow |
| Static IP | no | yes, per zone | n/a |
| Use for | web apps and APIs | high volume, non-HTTP, PrivateLink | firewalls and inspection appliances |
The Classic Load Balancer is the previous generation; don’t start there.
The pieces
- A listener waits on a port and protocol.
- Rules (ALB) are checked in priority order and pick an action: forward, redirect, a fixed response, or authenticate first.
- A target group lists targets (instances, IP addresses, a Lambda function) with a port and a health check.
aws elbv2 create-load-balancer --name web --type application --subnets subnet-a subnet-b
aws elbv2 create-target-group --name web --protocol HTTP --port 8080 \
--vpc-id vpc-... --health-check-path /healthz
aws elbv2 create-listener --load-balancer-arn ... --protocol HTTP --port 80 \
--default-actions Type=forward,TargetGroupArn=...
aws elbv2 create-rule --listener-arn ... --priority 10 \
--conditions Field=path-pattern,Values='/api/*' \
--actions Type=forward,TargetGroupArn=...
Real deployments use an HTTPS listener with a certificate from ACM and redirect port 80 to it. An ALB needs subnets in at least two zones. Its security group admits clients, and the targets admit only that group. Reach it by its DNS name, never by IP.
A forward action can weight two target groups, which is how blue/green and canary releases work. Stickiness pins a client to one target; prefer stateless services.
Health and draining
With default settings an ALB checks every 30 seconds, needs 5 successes to call a target healthy and 2 failures to call it unhealthy. That makes adding capacity slow, so tune it.
If all targets in a group are unhealthy, the ALB fails open and routes to all of them, on the theory that trying is better than certain failure. A too-strict health check can hide behind this.
When a target is removed it enters draining: no new requests, while in-flight ones finish, for up to the deregistration delay (300 seconds by default). Your application should finish requests on shutdown too.
Zones
Each enabled zone gets load balancer nodes. With cross-zone balancing each node spreads over all targets; without it, only over its own zone, so uneven zones mean uneven load. ALB has it on (you can disable it per target group). NLB has it off by default, and enabling it adds cross-zone data charges.
Reading errors
| Code | Usual direction to look |
|---|---|
| 502 | the target closed the connection or sent a malformed response |
| 503 | no registered targets to send to |
| 504 | the target did not answer in time, or could not be reached |
A classic 502: the application’s keep-alive timeout is shorter than the ALB’s idle timeout (60 seconds by default), so it closes a connection the balancer is about to reuse. Make the application’s longer.
Access logs say which target answered, with what status and how long it took. The client’s address arrives in X-Forwarded-For.
About the video
The embed is the first 36 minutes of AWS’s re:Invent 2025 deep dive on the evolution of load balancing. The chapters in that range cover load balancing basics, the underlying technology, ALB, NLB and Gateway Load Balancer. It is an advanced conference talk, so expect internals; the rest of the session (QUIC and newer features) is left out of the clip. I judged it from chapters and description, since transcripts couldn’t be fetched. The 2021 session in deeper is about choosing between them.
What was run: the four creation calls ran against moto, a local emulator, which showed the default health check values above but serves no traffic. No error code was produced or observed. Behaviour is from AWS documentation, checked in November 2026.
Where this fits
Compute is complete. The next group is where most data lives: S3 buckets, objects and consistency.
Check yourself
Clients must allow-list fixed IP addresses for your HTTPS service. Which load balancer gives you that?
A Network Load Balancer, which has a static address per zone and can use Elastic IPs. An ALB's addresses change; you can place an ALB behind an NLB if you need both.
An ALB returns 503. Where do you look first?
At the target group: whether any targets are registered and the listener rule points where you expect.
New instances take three minutes to be considered healthy with default settings and a 30 second interval. Why?
The default healthy threshold is 5 consecutive successes, so about 150 seconds of checks after the application starts answering. Lower the interval or threshold.
An NLB spans two zones with two targets in one and eight in the other, and cross-zone is off. How is traffic split?
Each zone's node gets about half and spreads it only over its own targets, so each of the two targets gets about 25% and each of the eight about 6%.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.