Elastic Load Balancing Explained: Application, Network and Gateway Load Balancers, Target Groups and Health Checks

AWS Technical Essentials 50 min min read Updated: Nov 17, 2026 Beginner
Elastic Load Balancing Explained: Application, Network and Gateway Load Balancers, Target Groups and Health Checks
Beginner Topic 1 of 3

Why a Load Balancer?

  • One server is a single point of failure and has limited power
  • A load balancer sits in front of several servers, spreads requests among them and stops sending traffic to broken servers
  • Users see one address while you can add or remove servers behind it
text Users ──► Load balancer (DNS name) ──► Server in AZ a ├─► Server in AZ b └─► Server in AZ c (unhealthy servers are skipped)

Types of Load Balancers

TypeWorks atBest forNotes
Application Load Balancer (ALB)Layer 7 (HTTP/HTTPS)Websites, APIs, microservices, containersRoutes by path, host name, headers. Supports WebSockets, redirects, authentication, WAF, Lambda targets
Network Load Balancer (NLB)Layer 4 (TCP/UDP/TLS)Extreme performance, low latency, static IP per AZ, non-HTTP protocolsMillions of requests per second
Gateway Load Balancer (GWLB)Layer 3Firewalls and inspection appliances from partnersTransparent traffic inspection
Classic Load BalancerLayer 4/7Old applications onlyDo not use for new work

Key Pieces of an ALB

PieceMeaning
ListenerChecks for connections on a port and protocol (for example HTTP 80, HTTPS 443)
RulesDecide what to do with a request: forward, redirect, return a fixed response. Match by path (/api/*), host (shop.example.com), header
Target groupA group of targets (EC2 instances, IP addresses, Lambda functions, containers) that receive traffic
Health checkRegular test of each target, for example GET /health expecting HTTP 200
Subnets / AZsThe balancer needs subnets in at least two AZs
Security groupControls who can reach the balancer. Servers should allow traffic only from the balancer's security group

Create an ALB Step by Step

  1. Launch two EC2 web servers in two AZs (use the nginx user data)
  2. Create a target group (instances, HTTP 80, health check path /) and register both servers
  3. Create an Application Load Balancer (internet-facing) in two public subnets with a security group allowing 80/443 from anywhere
  4. Add a listener on port 80 that forwards to the target group
  5. Wait until targets are healthy
  6. Open the ALB DNS name in a browser and refresh to see both servers answer
bash TG=$(aws elbv2 create-target-group --name web-tg --protocol HTTP --port 80 --vpc-id vpc-0abc --health-check-path /health --query 'TargetGroups[0].TargetGroupArn' --output text) aws elbv2 register-targets --target-group-arn $TG --targets Id=i-0aaa Id=i-0bbb ALB=$(aws elbv2 create-load-balancer --name web-alb --subnets subnet-a subnet-b --security-groups sg-alb --query 'LoadBalancers[0].LoadBalancerArn' --output text) aws elbv2 create-listener --load-balancer-arn $ALB --protocol HTTP --port 80 --default-actions Type=forward,TargetGroupArn=$TG aws elbv2 describe-target-health --target-group-arn $TG --query 'TargetHealthDescriptions[].[Target.Id,TargetHealth.State]' --output table

HTTPS and Security

  • Request a free certificate in AWS Certificate Manager (ACM) and add an HTTPS listener on 443
  • Redirect HTTP 80 to HTTPS 443 with a listener rule
  • Choose a modern security policy for TLS versions
  • Attach AWS WAF to an ALB to block common attacks
  • Keep servers in private subnets, with only the ALB in public subnets

Useful Settings

SettingMeaning
Cross-zone load balancingSpread traffic evenly across all targets in all AZs (always on for ALB)
Sticky sessionsSend the same user to the same server using a cookie (better to keep servers stateless)
Deregistration delayTime to finish in-flight requests before removing a target (default 300 s)
Idle timeoutHow long a connection can stay idle (default 60 s)
Access logsRequest logs saved to S3 for troubleshooting
Connection draining and slow startSmooth deployments and scaling

Troubleshooting

Error / symptomLikely cause
502 Bad GatewayServer crashed or sent an invalid response, or closed the connection
503 Service UnavailableNo healthy targets
504 Gateway TimeoutServer too slow, or blocked by security group or NACL
Targets unhealthyWrong health check path or port, app not running, server security group does not allow the balancer
Cannot open the ALB URLSecurity group on ALB, not in public subnets, no route to Internet Gateway

Practice

  1. Build the ALB with two servers and refresh the page to see load balancing
  2. Stop nginx on one server and watch it become unhealthy (and traffic still works)
  3. Add a path rule /api/* to a second target group
  4. Add an HTTPS listener with an ACM certificate
  5. Enable access logs to S3

Conclusion

A load balancer spreads traffic and hides failures. Use ALB for HTTP apps, NLB for TCP/UDP and static IPs, GWLB for inspection appliances. Understand listeners, rules, target groups and health checks, and read 502, 503 and 504 errors.

Quick Summary: why; types; pieces; create; HTTPS; settings; troubleshooting.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators