Elastic Load Balancer (ELB)
Load Balancers can be physical hardware or virtual software that accepts incoming traffic, and then distributes the traffic to multiple targets. They can balance the load via different rules. These rules vary based on types of load balancers.
Elastic Load Balancer (ELB) is the AWS solution for load balancing traffic and are 3 types available:
- Application Load Balancer ALB (HTTP/HTTPS)
- Network Load Balancer NLB (TCP/UDP)
- Classic Load Balancer CLB (Legacy)
ELB - The Rules of Traffic
Listeners
Incoming traffic is evaluated against listeners. Listeners evaluate any traffic that matches the Listeners port. For CLB, EC2 instances are directly registered to the Load Balancer.
Rules (Not available for CLB)
Listeners will then invoke rules to decide what to do with the traffic. Generally the next step is to forward traffic to a Target Group.
Target Groups (Not available for CLB)
EC2 instances are registered as targets to a Target Group
For Application Load Balancer or Network Load Balancer traffic is sent to the Listeners. When the port matches it when checks the rules what to do. The rules will forward the traffic to a Target Group. The target group will evenly distribute traffic to instances registers to that target Group.
For Classic Load Balancers traffic is sent to the Listeners. When the port matches it then forwards the traffic to any EC2 instances that are registered to the CLB. CLB does not allow you apply rules to listeners.
Application Load Balancer
Application Load Balancers are designed to balance HTTP and HTTPS traffic
They operate at Layer 7 of the OSI Model
ALB has a feature called Request Routing which allows you to add routing rules to your listeners based on the HTTP protocol.
Web Application Firewall (WAF) can be attached to the ALB. Great for Web Applications
Network Load Balancers
Network Load Balancers are designed to balance TCP/UDP
They operate at Layer 4 of the OSI Model
Can handle millions of requests per seconds while still maintaining extremely low latency.
Can perform Cross-Zone Load balancing
Great for Multiplayer Video Games or when network performance is critical
Classic Load Balancer
It was AWS first load balancer (legacy) Can balance HTTP, HTTPS or TCP traffic (not at the same time) It can use Layer 7-specific features (OSI Model) such as sticky sessions. It can also use strict Layer 4 (OSI Model) balancing for purely TCP applications. Can preform Cross-Zone Load Balancing It will respond with a 504 error (timeout) if the underlying application is not responding. (at the web-server or database level) Not recommended for use, instead use NLB or ALB
Sticky Sessions
Sticky Sessions is an advanced load balancing method that allows you to bind a user’s session to a specific EC2 instance.
Ensures all requests from that session are sent to the same instance.
Typically utilized with a Classic Load Balancer
Can be enabled for ALB though can only be set on a Target Group not individual EC2 instances. Cookies are used to remember which EC2 instance.
Useful when specific information is only stored locally on a single instance
X-Forwarded-For (XFF) Header
If you need the IPv4 address of a user, check the X-Forwarded-For header
The X-Forwarded-For (XFF) header is a command method for identifying the originating IP address of a client connecting to a web server through an HTTP proxy or load balancer
ELB - Health Checks
Instances that are monitored by the ELB report back Health Checks as InService, or OutofService
Health Checks communicate directly with the instance to determine its state
ELB does not terminate unhealthy instances. It will just redirect to healthy instances
Cross-Zone Load Balancing
Only available for Classic and Network Load Balancers
CrossZone Enabled requests are distributed evenly across the instances in all enabled AZs.
CrossZone disabled requests are distributed only in its AZs.
Request Routing
Apply rules to incoming request and then forward or redirect traffic.
✅ Host header ✅ Http header ✅ Source IP ✅ Http header method ✅ Path ✅ Query string