How it works
The explanation, with examples you can run.
Which one
| Application Load Balancer | Network Load Balancer | |
|---|---|---|
| Layer | 7 (HTTP, HTTPS, gRPC, WebSockets) | 4 (TCP, UDP, TLS) |
| Routing | Host, path, headers, query strings, methods | Port and protocol only |
| Addresses | DNS name; IPs can change | Static IP per zone, optional Elastic IP |
| Typical use | Web apps and APIs, several services behind one name | Non-HTTP protocols, very high connection rates, fixed IPs for allow-lists |
A Gateway Load Balancer also exists, for inserting third-party firewalls and appliances into traffic. Both ALB and NLB support security groups now, so the target's group can admit only the balancer's group.
Health checks
The balancer probes each registered target on a port and path you choose:
HealthCheckPath /healthzHealthCheckIntervalSeconds 30 # default for instance and ip targetsHealthCheckTimeoutSeconds 5UnhealthyThresholdCount 2 # consecutive failures before out of serviceHealthyThresholdCount 5 # consecutive successes before back in serviceMatcher 200 # HTTP codes that count as healthyWith these defaults, a target that dies keeps receiving traffic for up to about a minute, and a recovered one waits about two and a half minutes before it gets traffic again. Tighter intervals react faster but generate more probe load.
What the health check should test matters more than its timing. A check that queries a shared database marks every target unhealthy when the database is slow. The ALB then fails open and sends traffic to all targets regardless, which is better than nothing, but you have lost the ability to route around a genuinely broken instance. Keep the check about the target itself (is the process up and able to serve), and handle dependency failures in the application, for example with timeouts and degraded responses.
Other settings that matter
- Deregistration delay (default 300 seconds) keeps in-flight requests going while a target is removed. Lower it for short requests so deploys are not slowed for minutes; make sure your app drains on SIGTERM within it.
- Cross-zone load balancing is on for ALBs, off by default for NLBs; with it off, each zone's node only uses targets in its own zone, so uneven target counts give uneven load.
- Slow start ramps traffic to new targets gradually, useful for apps with cold caches or JIT warm-up.
- Idle timeout (60 seconds by default on ALB) closes quiet connections; keep your server's keep-alive timeout longer than it, or clients will see occasional 502s.
Check yourself
3 questions. Get them all right to finish this topic.
0 of 3 right so far. Get all three to finish this topic.