It is a managed load balancer
- AWS guarantees that it will be working
- AWS take care of upgrades, maintenance, high availability. Only a few config knobs
Health checks are crucial. Load balancer generally uses a port and an endpoint (like /health) to check.
Types of ELB
- Application Load Balancer: v2 new gen, HTTP, HTTPS, WebSocket
- Network Load Balancer: v2 new gen, TCP, TLS, UDP
- Gateway Load Balancer: Operates at layer 2, IP protocol
Security Groups
- Load balancer should allow 443 and 80 from everywhere
- EC2 should allow only from the security group of the load balancer
Sticky Sessions (Session Affinity)
It is possible to implement stickiness so that the same client is always redirected to the same instance.
It works for Classic Load Balancer, Application Load Balancer and Network Load Balancer
- It uses cookies for stickiness until the expiration date you set (NLB doesn’t use cookies)
TIP
Both Load Balancer and Target Group has sticky sessions.
- When you set stickiness in load balancer (which is done in the listener), it sticks to the same Target Group.
- When you set stickiness in target group, it sticks to the same instance.
Use case: To make sure the user doesn’t lose his session data. But this might bring imbalance to the load over the backend EC2 instances
You can edit this in target groups
Cookie Types
-
Application-based Cookies
- Custom cookie
- Generated by the target
- Can include any custom attributes required by the application
- Cookie name must be specified individually for each target group
- Don’t use AWSALB, AWSALBAPP, or AWSALBTG (reserved for use by the ELB)
- Application cookie
- Generated by the load balancer
- Cookie name is AWSALBAPP
- Custom cookie
-
Duration-based Cookies
- Cookie generated by the load balancer
- Cookie name is AWSALB for ALB, AWSELB for CLB
Cross-Zone Load Balancing
It can be used when there is an imbalance of computational power between AZ. When there are 2 load balancers, one having 2 EC2 instances, one having 10 EC2 instances. If you enable cross-zone load balance, each load balancer will act like they have 12 EC2 instances instead of the ones in their AZ.
Application Load Balancer
- Enabled by default (can be disabled at the Target Group level)
- No charges for inter AZ data
Network Load Balancer & Gateway Load Balancer
- Disabled by default
- You pay charges ($) for inter AZ data if enabled
Classic Load Balancer
- Disabled by default
- No charges for inter AZ data if enabled
Connection Draining
Also called Deregistration Delay
- Time to complete “in-flight requests” while the instance is de-registering or unhealthy
- Stops sending new requests to the EC2 instance which is de-registering
- Between 1 to 3600 seconds (default: 300 seconds)
- Can be disabled (set value to 0)
- Set to a low value if your requests are short