Xoxoftware - XOXO Creative Studio | Web & Mobile App Development | Fred Cheung | Hong Kong
AWSNetworking

Elastic Load Balancing

Managed load balancers — ALB, NLB, and GWLB covering target groups, listeners, sticky sessions, cross-zone balancing, and health checks.

Overview

Elastic Load Balancing (ELB) automatically distributes incoming traffic across multiple targets — EC2 instances, containers, IP addresses, or Lambda functions — across one or more Availability Zones for high availability and fault tolerance.

AWS offers three load balancer types: Application Load Balancer (ALB) for HTTP/HTTPS, Network Load Balancer (NLB) for TCP/UDP/TLS at ultra-low latency, and Gateway Load Balancer (GWLB) for inline third-party virtual appliances.


Core Concepts

ConceptDescription
Load BalancerThe entry point that receives and distributes traffic to registered targets
ListenerChecks for connection requests on a configured protocol and port; routes to target groups
Target GroupA set of registered targets (instances, IPs, Lambda) with health check configuration
TargetAn individual destination (EC2 instance, IP address, Lambda function, or ALB)
Health CheckPeriodic probes to determine if a target is healthy and eligible to receive traffic
Availability ZoneELB distributes traffic across all enabled AZs
Cross-Zone Load BalancingDistributes traffic evenly across all targets in all AZs, not just within each AZ
Sticky SessionsBinds a user's session to a specific target using cookies (application or duration-based)

ALB vs NLB vs GWLB

FeatureALB (Application)NLB (Network)GWLB (Gateway)
OSI LayerLayer 7 (HTTP/HTTPS)Layer 4 (TCP/UDP/TLS)Layer 3 (IP) + Layer 4
ProtocolHTTP, HTTPS, gRPC, WebSocketTCP, UDP, TLSGENEVE encapsulation
PerformanceGood; processes HTTP headersUltra-low latency; millions of req/secTransparent inline inspection
Static IPNo (use Global Accelerator for static)Yes — one static IP per AZNo
SSL/TLS terminationYes (ACM integration)Yes (TLS listener)N/A
RoutingPath, host, header, query string, source IPPort-based onlyN/A (transparent pass-through)
Target typesInstance, IP, LambdaInstance, IP, ALBInstance, IP
Use caseWeb apps, microservices, APIsGaming, IoT, financial, static IP needsFirewalls, IDS/IPS, deep packet inspection

SAA/SAP Tip: Choose ALB for HTTP/HTTPS workloads that need path-based or host-based routing. Choose NLB when the question mentions "ultra-low latency," "millions of requests," "static IP," or non-HTTP protocols like TCP/UDP.


ALB Routing Rules

ALB supports advanced content-based routing via listener rules:

Condition TypeRoutes Based OnExample
PathURL path/api/* → API target group
Host headerDomain name in Host headerapi.example.com → API TG
HTTP headerCustom header valueX-Custom: mobile → Mobile TG
HTTP methodGET, POST, etc.POST → Write TG
Query stringQuery parameter key/value?platform=mobile → Mobile TG
Source IPClient IP CIDR10.0.0.0/8 → Internal TG

Actions: Forward, Redirect (301/302), Fixed Response (e.g., 503 maintenance page), Authenticate (Cognito/OIDC).


Health Checks

SettingALBNLB
ProtocolHTTP, HTTPSTCP, HTTP, HTTPS
PathConfigurable (e.g., /health)Configurable for HTTP/HTTPS checks
Interval5–300 seconds10 or 30 seconds
Healthy threshold2–10 consecutive successes2–10
Unhealthy threshold2–10 consecutive failures2–10

Exam Trap: NLB health checks can use TCP (connection only) or HTTP/HTTPS. If targets use HTTP but the health check is TCP, a half-open or crashed application may still appear "healthy." Use HTTP health checks to verify application-level health.


Sticky Sessions (Session Affinity)

Cookie TypeGenerated ByDurationUse Case
Duration-basedELB1 s – 7 daysSimple session pinning
Application-basedApplicationSet by application cookieApplication-managed sessions

Exam Trap: Sticky sessions can cause uneven load distribution. If one target accumulates long-lived sessions, it may become overloaded while others are idle. For stateless architectures, store session data in ElastiCache or DynamoDB instead.


Cross-Zone Load Balancing

Load BalancerDefaultCost
ALBEnabledFree
NLBDisabledCharged per inter-AZ GB transferred
GWLBDisabledCharged per inter-AZ GB transferred

Without cross-zone balancing, traffic is distributed only among targets within the same AZ as the load balancer node — leading to imbalanced load if AZs have different numbers of targets.


Connection Draining (Deregistration Delay)

When a target is deregistered or becomes unhealthy, ELB allows in-flight requests to complete before removing it.

  • Default: 300 seconds
  • Set to 0 for instant deregistration (useful for short-lived tasks)
  • Critical for graceful shutdowns during deployments and scale-in

Common Use Cases

  • Multi-tier web applications — ALB routes /api/* to backend services and /* to frontend servers.
  • Microservices — ALB host-based routing directs auth.example.com and orders.example.com to different target groups.
  • TCP/UDP services — NLB for gaming servers, IoT endpoints, or financial trading platforms requiring static IPs.
  • Hybrid targets — NLB with IP-based targets to route to on-premises servers via Direct Connect.
  • Inline security appliances — GWLB transparently routes traffic through firewalls or IDS/IPS before reaching targets.
  • SSL offloading — ALB terminates TLS, reducing certificate management and compute on backend instances.

SAA/SAP Exam Tips

SAA/SAP Tip: When a question requires a static IP address for a load balancer, the answer is NLB (one Elastic IP per AZ) or NLB fronting an ALB. ALB does not support static IPs natively.

Exam Trap: ALB targets can include Lambda functions — a single ALB can serve both container-based and serverless targets using different target groups and routing rules.

SAA/SAP Tip: GWLB appears in security-focused questions: "inspect all traffic with a third-party firewall" or "inline IDS/IPS." It uses GENEVE encapsulation and is transparent to the application.


Cross-Cloud Equivalents

ProviderService / SolutionNotes
AWSElastic Load BalancingBaseline
AzureAzure Application Gateway (L7) / Azure Load Balancer (L4)Separate services for L4 and L7
GCPGoogle Cloud Load BalancingGlobal by default; supports L4 and L7
On-PremisesNGINX, HAProxy, F5 BIG-IPSoftware or hardware load balancers

Pricing Model

DimensionALBNLB
Fixed hourly charge~$0.0225/hr~$0.0225/hr
Usage metricLCU (Load Balancer Capacity Unit)NLCU (Network LCU)
LCU/NLCU includesNew connections, active connections, processed bytes, rule evaluationsNew connections/flows, active connections/flows, processed bytes
Data processingIncluded in LCUIncluded in NLCU

GWLB uses GWLBE (Gateway Load Balancer Endpoint) pricing: per hour + per GB processed.


Built by Fred Cheung @CookedRicer · Powered by Fumadocs & Github Copilot

On this page