Load Balancers
Overview
Elastic Load Balancing (ELB) automatically distributes incoming traffic across multiple targets — EC2 instances, containers, IP addresses or Lambda functions — in one or more Availability Zones. It checks the health of every target and sends requests only to healthy ones, which is the key to both scalability and high availability.
AWS offers several types. The Application Load Balancer (ALB) works at Layer 7 and understands HTTP/HTTPS, so it can route by URL path or host name. The Network Load Balancer (NLB) works at Layer 4 for extreme performance, static IPs and TCP/UDP/TLS traffic. The Gateway Load Balancer (GWLB) inserts third-party virtual appliances such as firewalls into your traffic path. The Classic Load Balancer is the legacy option.
Choosing the right load balancer for a scenario is one of the most frequent exam question styles, so learn the feature differences well.
Key Concepts
- ALB (Layer 7): HTTP/HTTPS/gRPC/WebSocket, path, host, header, query-string routing, redirects, fixed responses, Lambda targets, integrates with WAF, Cognito and OIDC authentication.
- NLB (Layer 4): TCP/UDP/TLS, millions of requests per second, ultra-low latency, static IP / Elastic IP per AZ, preserves client source IP, supports PrivateLink.
- GWLB (Layer 3): deploys, scales and manages virtual appliances (firewalls, IDS/IPS) using the GENEVE protocol on port 6081.
- Target groups hold targets (instance, IP, Lambda, ALB) and define the health check; a listener rule forwards to a target group.
- Cross-zone load balancing is enabled by default on ALB (no charge) and disabled by default on NLB/GWLB (charges for inter-AZ data when enabled).
- Sticky sessions (session affinity) use a cookie so a client keeps hitting the same target; deregistration delay (default 300 s) drains in-flight requests.
- HTTPS: terminate TLS at the load balancer with an ACM certificate; SNI lets one listener serve multiple certificates/domains.
- The X-Forwarded-For header carries the client IP through an ALB; NLB preserves the source IP natively (for instance targets).
- ELB is a Regional service; place nodes in at least two AZs. Use Route 53 or Global Accelerator for multi-Region distribution.
Detailed Notes
Choosing a load balancer
| Feature | ALB | NLB | GWLB | Classic (legacy) |
|---|---|---|---|---|
| OSI layer | 7 | 4 | 3 (+4) | 4 and 7 |
| Protocols | HTTP, HTTPS, gRPC, WebSocket | TCP, UDP, TLS, TCP_UDP | IP (GENEVE 6081) | TCP, SSL, HTTP, HTTPS |
| Static / Elastic IP | No (use DNS name, or front with Global Accelerator) | Yes, per AZ | No | No |
| Routing | Path, host, header, method, query, source IP | Port/protocol | Flow hash to appliances | Basic |
| Targets | Instance, IP, Lambda | Instance, IP, ALB | Instance, IP | Instance |
| Security groups | Yes | Yes (since 2023) | No | Yes |
| Cross-zone default | On | Off | Off | Off (console: on) |
| Best for | Web apps, microservices, containers | Extreme performance, static IPs, non-HTTP, PrivateLink | Inline security appliances | Legacy only |
Listeners, rules and target groups
A listener checks for connections on a protocol and port (for example HTTPS:443). For ALB, rules evaluate conditions in priority order and forward, redirect or return a fixed response.
Listener:
Port: 443
Protocol: HTTPS
Certificates: [arn:aws:acm:us-east-1:111122223333:certificate/abc]
Rules:
- Priority: 10
Condition: { PathPattern: "/api/*" }
Action: { Type: forward, TargetGroup: api-tg }
- Priority: 20
Condition: { HostHeader: "admin.example.com" }
Action: { Type: forward, TargetGroup: admin-tg }
- Default: { Type: forward, TargetGroup: web-tg }
Health checks
- Protocol/port/path (ALB, e.g.
/healthexpecting 200–399), interval (default 30 s), healthy threshold (default 5), unhealthy threshold (default 2), timeout (default 5 s). - Targets that fail are removed from rotation; if all targets are unhealthy, ALB fails open and routes to all.
- A security group on targets must allow the ALB's health checks and traffic (reference the ALB SG).
Cross-zone load balancing
| Mode | Behaviour |
|---|---|
| Enabled | Each load balancer node spreads traffic evenly across all registered targets in all AZs |
| Disabled | Each node only sends to targets in its own AZ — traffic can be uneven if AZs have different target counts |
ALB: always on at the load-balancer level (can be turned off per target group), no inter-AZ charge. NLB/GWLB: off by default, inter-AZ data charges apply when on.
Sticky sessions
- ALB: duration-based cookie (AWSALB) or application-based cookie; set per target group. NLB: flow-based (source IP) affinity for TCP.
- Prefer stateless apps with sessions in ElastiCache or DynamoDB; stickiness can cause uneven load.
Security and TLS
- TLS termination on the ALB with ACM certificates; re-encrypt to targets if required (end-to-end).
- SNI supports multiple certificates on one listener (ALB and NLB).
- AWS WAF attaches to an ALB (not NLB). Use mutual TLS (mTLS) on ALB for client certificates.
- Security groups: ALB/NLB allow inbound from the internet; targets allow inbound only from the load balancer's SG.
- ALB access logs go to S3; use CloudWatch metrics (RequestCount, TargetResponseTime, HTTPCode_ELB_5XX, UnHealthyHostCount).
Internet-facing vs. internal
- Internet-facing nodes get public IPs and live in public subnets.
- Internal load balancers have private IPs only and sit between application tiers or in front of PrivateLink services.
- DNS name format:
my-alb-123456.us-east-1.elb.amazonaws.com— always use the DNS name or a Route 53 alias, never node IPs (they change).
Patterns
- NLB in front of ALB gives a static IP with Layer 7 routing.
- ALB + Lambda for serverless HTTP backends.
- GWLB + appliance fleet for centralised inspection with Transit Gateway.
- NLB + PrivateLink to expose a service privately to other VPCs.
Limits and details
| Item | Value |
|---|---|
| ALB rules per listener | 100 (default) |
| ALB idle timeout | 60 seconds (adjustable) |
| Deregistration delay | 300 seconds default (0–3600) |
| Targets per ALB target group | 1,000 |
| NLB latency | Hundreds of microseconds |
| Max HTTP request header | 64 KB total, 16 KB per line (ALB) |
Real World Example
Scenario — a bank modernises its online portal.
The bank's retail site is split into services: /accounts, /payments and /support. They deploy a single internet-facing ALB with path-based rules that forward to separate target groups (EC2 Auto Scaling groups and ECS tasks). The ALB terminates TLS using ACM certificates with SNI for the retail and corporate domains, is protected by AWS WAF against injection and bot traffic, and authenticates staff to the admin path with Cognito/OIDC.
Partner banks must whitelist fixed IP addresses to call the payments API, so the payments entry point is an NLB with one Elastic IP per AZ forwarding to an internal ALB. A Gateway Load Balancer fleet running a third-party next-generation firewall inspects all east-west traffic via Transit Gateway to satisfy compliance.
Health checks hit /health, cross-zone is enabled, and a 120-second deregistration delay lets in-flight payments complete during deployments. During a data-centre-level failure in one AZ, targets there fail health checks and traffic automatically flows to the remaining AZs with no customer-visible outage.
Architecture Diagram
The ALB terminates TLS, applies WAF and routes by path to separate target groups spread across AZs.
- 1Users resolve the ALB DNS name (via Route 53 alias) and connect over HTTPS; WAF filters malicious requests.
- 2The ALB terminates TLS and evaluates listener rules in priority order.
- 3Matching requests are forwarded to the target group for that path; only healthy targets in any AZ receive traffic (cross-zone).
- 4Health checks continually remove failed targets and Auto Scaling replaces them.
Best Practices
- ✓Pick the right type: ALB for HTTP/S, NLB for TCP/UDP, static IPs or extreme performance, GWLB for virtual appliances.
- ✓Register targets in at least two AZs and keep cross-zone enabled when target counts are uneven.
- ✓Terminate TLS with ACM certificates, redirect HTTP to HTTPS, and use modern security policies.
- ✓Lock targets down: their security groups should accept traffic only from the load balancer's security group.
- ✓Design meaningful health checks (a lightweight
/healthendpoint that checks dependencies sensibly) and tune thresholds. - ✓Use deregistration delay and connection draining for zero-downtime deployments.
- ✓Enable access logs, CloudWatch alarms (5XX, latency, unhealthy hosts) and AWS WAF where applicable.
- ✓Use Route 53 alias records to the load balancer; never hard-code node IP addresses.
Common Interview Questions
Exam Tips
SAA-C03 focus
- HTTP/HTTPS, path/host routing, WAF, Lambda targets -> ALB. TCP/UDP, static IP, extreme performance, PrivateLink -> NLB. Firewall appliances -> GWLB.
- Static IP with Layer 7 routing: put an NLB in front of the ALB or use Global Accelerator.
- Cross-zone: ALB on by default (no charge); NLB/GWLB off by default (charges when enabled).
- Sticky sessions pin a client to a target; deregistration delay drains connections; both are common "deployment" or "session" answers.
- WAF attaches to ALB (and API Gateway/CloudFront), not NLB.
- To terminate TLS and manage certificates centrally, use ACM on the load balancer; SNI for multiple domains.
- Load balancers are Regional; for multi-Region failover/latency use Route 53 or Global Accelerator.
- Combine ASG + ELB health checks so unhealthy instances are replaced automatically.
Finished this lesson?
0 of 64 lessons done · 0% of the course

