What is Load Balancer?
An AWS Load Balancer is a service that automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances, containers, and IP addresses, within one or more availability zones.
The primary purpose of a load balancer is to improve the availability and fault tolerance of your application.
Different types of Load Balancer.
Application Load Balancer (ALB):
Works at the application layer (Layer 7 of the OSI model).
Ideal for routing HTTP/HTTPS traffic.
Supports content-based routing, enabling you to route requests based on the content of the request (e.g., host-based routing).
Provides support for WebSocket and HTTP/2 protocols.
Well-suited for modern web applications.
Network Load Balancer (NLB):
Operates at the transport layer (Layer 4 of the OSI model).
Routes traffic based on IP protocol data.
Best suited for TCP and UDP traffic.
Offers high-performance, low-latency balancing.
Ideal for applications that require static IP addresses.
Classic Load Balancer:
The oldest type of load balancer in AWS.
Supports both Layer 4 and Layer 7 load balancing.
Useful for applications that rely on the older EC2-Classic network.
How Load Balancer works?
Traffic Distribution:
When a client sends a request to your application, it is directed to the load balancer.
The load balancer examines the incoming traffic and forwards it to one of the registered targets.
Health Checks:
Load balancers regularly perform health checks on registered targets to ensure they are responsive and healthy.
Unhealthy targets are automatically removed from the load balancer's rotation.
Load Balancing Algorithms:
Load balancers use various algorithms to distribute traffic among healthy targets, such as Round Robin, Least Outstanding Requests, or IP Hash.
These algorithms help optimize the distribution of requests based on different factors.
Auto Scaling Integration:
Load balancers work seamlessly with AWS Auto Scaling, enabling your application to scale in or out based on demand.
New instances can be automatically registered with the load balancer when added, and instances can be deregistered when they are terminated or become unhealthy.