Volume 2 · Chapter 12 — AWS Networking Deep Dive (VPC)
Elastic Load Balancing in Depth
12.1 Introduction
The load-balancing chapter introduced ALB and NLB; the exam wants the full comparison including the Gateway Load Balancer and the legacy Classic Load Balancer, plus the mechanics - target groups, listeners and rules, sticky sessions, cross-zone load balancing, connection draining, and TLS handling. This chapter provides that depth, because choosing and configuring the right load balancer is a constant exam theme.
12.2 The Four Load Balancer Types
AWS has four load balancers. The**Application Load Balancer (ALB)operates at Layer 7 (HTTP/HTTPS), routing on content - path, host header, HTTP headers, query strings, source IP - to different target groups, and supports containers, Lambda targets, and authentication; it’s the default for web and microservices. TheNetwork Load Balancer (NLB)operates at Layer 4 (TCP/UDP/TLS), handles millions of requests per second at ultra-low latency, preserves the client source IP, and provides astatic IP per AZ(and supports Elastic IPs) - for extreme performance, non-HTTP protocols, or when you need a fixed IP. TheGateway Load Balancer (GWLB)operates at Layer 3, transparently inserting third-party virtual appliances (firewalls, IDS/IPS) into the traffic path using the GENEVE protocol - for inline security inspection. TheClassic Load Balancer (CLB)**is the legacy Layer 4/7 balancer, now superseded by ALB/NLB. The exam decision: ALB for HTTP content-based routing, NLB for performance/static IP/ non-HTTP, GWLB for inline appliances, CLB only for legacy.
flowchart TD
Q{Load balancing need?} -->|HTTP/HTTPS, content-based routing| ALB[Application LB - Layer 7]
Q -->|Extreme perf, TCP/UDP, static IP| NLB[Network LB - Layer 4]
Q -->|Insert firewall/IDS appliances inline| GWLB[Gateway LB - Layer 3, GENEVE]
Q -->|Legacy only| CLB[Classic LB]
ALB --> TG[Target groups: instances, IPs, Lambda, containers]
NLB --> TG 12.3 Target Groups, Listeners, and Health Checks
Load balancers route totarget groups- collections of registered targets (EC2 instances, IPs, Lambda functions, or containers) with their own health-check configuration. Alistenerchecks for connections on a port/protocol; on an ALB, listenerrulesevaluate conditions (path, host, header) in priority order to forward to the right target group, enabling one ALB to front many services (e.g./payments→ payments group,/accounts→ accounts group). Health checks probe each target and remove unhealthy ones from rotation - correct health checks are what make rolling deployments and instance replacement seamless. This target-group-and-rule model is how modern microservice routing is expressed on an ALB.
12.4 Sticky Sessions, Cross-Zone, and Connection Draining
Several tested behaviors:Sticky sessions(session affinity) bind a client to the same target using a cookie - needed for stateful apps, though the better pattern is stateless apps with external session state.Cross-zone load balancingdistributes requests evenly across all targets in all AZs regardless of which AZ received the request; it’son by default and free for ALB, butoff by default for NLB(and enabling it may incur cross-AZ charges) - a commonly-tested asymmetry.Connection draining(deregistration delay) lets in-flight requests to a target complete before it’s removed, so deployments and scale-in don’t drop active connections. These settings determine correctness during scaling and deployment.
12.5 TLS Termination, SNI, and Source IP
Load balancers commonlyterminate TLS, offloading encryption using a certificate from AWS Certificate Manager (ACM), which handles free public certificates and auto-renewal.SNI (Server Name Indication)lets one ALB/NLB listener serve multiple TLS certificates for multiple domains on the same IP. Because the load balancer terminates the connection, the backend sees the load balancer’s IP - so the original client IP is passed in theX-Forwarded-Forheader (ALB) or preserved directly by NLB. For end-to-end encryption you can also re-encrypt to the backend. The exam expects: TLS termination with ACM, SNI for multiple certs, and X-Forwarded-For (ALB) or source-IP preservation (NLB) for the real client address.
12.6 Banking Production Scenario
A bank fronts its customer platform with an ALB across three AZs, terminating TLS with an ACM certificate (SNI serving several domains), with listener rules routing by path to per-microservice target groups, each health-checked, and cross-zone balancing on by default. Connection draining lets in-flight payment requests finish during deployments and scale-in. Backends read the true client IP from X-Forwarded-For for fraud signals. A partner integration that needs a fixed IP and extreme throughput uses an NLB with an Elastic IP per AZ. For inline intrusion prevention on a sensitive tier, traffic passes through a Gateway Load Balancer to a third-party firewall appliance. Sessions are stateless (state in a cache), avoiding sticky-session pitfalls. This precise ELB selection and configuration is core architect competence.
12.7 Chapter Revision Notes
- ALB (L7, content routing, containers/Lambda), NLB (L4, ultra-low latency, static IP, source-IP preservation, non-HTTP), GWLB (L3, inline appliances via GENEVE), CLB (legacy).
- Target groups hold targets with health checks; ALB listener rules route by path/host/header to different groups (one ALB, many services).
- Sticky sessions bind a client to a target (prefer stateless + external state); cross-zone LB is on-by-default/free for ALB, off-by-default for NLB.
- Connection draining (deregistration delay) lets in-flight requests finish during deploy/scale-in.
- TLS termination uses ACM (free auto-renewing certs); SNI serves multiple certs on one listener; client IP via X-Forwarded-For (ALB) or preserved by NLB.