What is Load balancing?
Load balancing is the process of distributing network traffic across multiple servers. It ensures that no single server bears too much demand.
The load balancers are servers that forward traffic to multiple servers downstream.
For example, we have 3 EC2 instances/ VMs and they are going to be connected to an elastic load balancer, now, for example, there are 3 users who are directly connecting to your elastic load balancer, then it will send each one of the user’s request to 3 of the different server, it will distribute the traffic equally into the instances.
The users will not know which backend EC2 instance they are connected to. The ELB will take care of that part. They just know they have to connect to ELB only and that gives them one point of contact.
Reference images from https://www.cloudflare.com/learning/performance/what-is-load-balancing/
Benefits of load balancing
Improves application responsiveness
Increases availability of applications and websites for users
Optimizes network performance, reliability, and capacity
Reduces latency
Avoids unevenly overloading some compute nodes while other compute nodes are left idle
Do regular health checks on your instances
Enforce stickiness with cookies
How load balancing works
Load balancing distributes network traffic across a pool of servers known as a server farm.
It distributes traffic among different instances of the same application.
To create a fault-tolerant system, it's common to run multiple instances of each application.
Whenever one service needs to communicate with another, it needs to pick a particular instance to send its request.
AWS ELB (Elastic Load balancer) and Why use it.
An ELB (Elastic Load Balancer) is a managed load balancer.
AWS guarantees that it will be working
AWS will take care of the upgrades, maintenance and high availability.
Reduce your efforts to set up the Load balancing manually.
It is integrated with many AWS offerings/ services.
Health Checks
Health checks are a way for ELB to verify the EC2 instances are properly working. if they are not working properly then we don’t want to send any traffic to that instance.
The health check is done through a port and a route (/health is common), It helps the ELB to understand if the Instances are available to reply to the requests. If the instance is not healthy then ELB will not send any traffic to the instance.
Types of Load balancer on AWS
AWS has 4 kinds of managed Load balancers.
Classic Load Balancer (Old gen)-2009-CLB
- HTTP, HTTPS, TCP, SSL
Application Load Balancer
- HTTP, HTTPS, WebSocket
Network Load Balancer
- TCP, TLS, UDP
Gateway Load Balancer
- Operates at layer 3 (Network Layer) - IP Protocol
Overall, it recommends using the newer generation load balancer as it provides more features.
Load Balancer Security Groups
We can enforce security group rules to allow or block the access for the users/ group of users, which is an enhanced security mechanism.