ELB

Elastic Load Balancer

Sticky session |

Overview

  • Distribute traffic across AZs.

  • AWS has 4 kinds of load balancers:

    • 3 popular ELB are:

-ALB (L7)NLB (L4)CLB (old)

protocol

HTTP, HTTPS, Websocket, gRPC

TCP, TLS (secure TCP), UDP

HTTP, HTTPS, TCP, SSL

DNS Name

Yes

Yes

Yes

Static IP

No

Yes

No

Benefit

route traffic to different Target group based on URL Path, Hostname, HTTP headers, and Query Strings.

  • Highest performance

  • Lowest latency

Target group

  • EC2 instance

  • private IP add

  • ALB

Health check

Support HTTP, HTTPS, TCP

Note

  • Reserved cookie names: AWSALB, AWSALBAPP, AWSALBTG.

  • To get the client's IP address, ALB adds an additional header called X-Forwarded-For contains the client's IP address.

has 1 static IP /AZ -> can attach Elastic IP

  • Gateway Load Balancer (L3 - Network layer)

Use cases


Features

ELB Sticky Session

  • Ensures traffic for the same client is always redirected to the same target (e.g., EC2 instance). This helps that the client does not lose his session data. To use sticky sessions, the client must support cookies.

  • Sticky sessions are enabled at the target group level.

  • ALB use the Expires attribute in the cookie header instead of the Max-Age attribute.

  • Sticky sessions rely on a cookie that is not going to be consistent across devices.

Sticky sessions are not supported if cross-zone load balancing is disabled.

With cross-origin resource sharing (CORS) requests, some browsers require SameSite=None; Secure to enable stickiness.

ELB Health Checks

  • When you enable ELB Health Checks, your ELB won't send traffic to unhealthy (crashed) EC2 instances.

  • When an EC2 instance fails the ALB Health Checks, it is marked unhealthy and will be terminated while the ASG launches a new EC2 instance.

Cross Zone Load Balancing

When Cross-Zone Load Balancing is enabled, ELB distributes traffic evenly across all registered EC2 instances in all AZs.

ALBNLBCLB

enabled by default

disabled by default

disabled by default

free

$ for inter-AZ

free

SSL certificate

Manage certificates using ACM (AWS Certificate Manager)

Server Name Indication

Allow you load multi SSL certificates on one listener.


Trivia

  • Only NLB provides both static DNS name and static IP. While, ALB & CLB provide a static DNS name but it does NOT provide a static IP.

  • When using an ALB to distribute traffic to your EC2 instances, the IP address you'll receive requests from will be the ALB's private IP addresses. To get the client's IP address, ALB adds an additional header called X-Forwarded-For contains the client's IP address.

  • ELB waits 300 seconds before the completion of the deregistration process, which can help in-flight requests to the target become complete. To change the amount of time that Elastic Load Balancing waits, update the deregistration delay value.

  • Only ALB support gRPC.


Concepts

  • gRPC (Remote Procedure Call): a protocol, a way that different parts of a computer program can talk to each other, even if they are on different computers or in different places.

Last updated