Overview of Load Balancers
What is a Load Balancer?
Elastic Load Balancer distributes traffic/load over several instances/resources and monitors the instances/resources and reroutes traffic away from unhealthy instances.
There are both hardware and software load balancers, while hardware load balancers are good for performance intensive applications, software load balancers are highly flexible and may run on the same machine on which the application is running giving it access to more real time data, it can also run on bare metal machines as well as hypervisor giving it a big platform independence to perform on.
Benefits of using Load Balancers
- Reduced Downtime : There are multiple instances present to which the traffic is being routed to, if by any chance a couple of instances go down/fail, the traffic which was being sent to these instances is automatically rerouted to other instances which are healthy. This can also be useful while updating the website as well.
- Scalable : Load Balancers manage traffic across multiple servers which keeps the response time low for client requests and keep the website working in a healthy condition.
- Increased Flexibility : You can shift the load balancer to passive mode where all the traffic is being routed to only a single server/set of servers while the others are undergoing maintenance. Once the update/maintenance task is finished, load balancer can be again set in active mode.
- Redundancy : Whenever an instance fails/goes down, the traffic which was being routed to that instance is automatically sent to other healthy instances.
- Efficiency : Load Balancer keeps checking the health/how busy an instance is to make sure no instance is overloaded with requests and hence reduces response time of incoming requests.
- Session Persistence : Maintains a single server which serves a single user throughout their session so that there is no transaction failure or data loss.
Types of Load Balancing
- SDN : (Software Defined Networking ) Separates control plane from the data plane. Leverages network layer information to decide where to send network traffic. This is accomplished through layer 4 load balancing, which is designed to handle all forms of TCP/UDP traffic. Network load balancing is considered the fastest of all the load balancing solutions, but it struggles in terms of distribution of traffic across servers.
- UDP : Based on UDP routing protocol in which there is high bandwidth due to it is used for live broadcasts and gaming streams, when speed is important, it does not provide health checks since they are time consuming.
- TCP : Load balancing for TCP traffic, it is reliable and error checked, due to which data is delivered completely.
- SLB : (Server Load Balancer) Uses a series of Load Balancing algorithms, prioritises responding to clients with specific requests, distributes client traffic to ensure consistent high performance delivery.
- Virtual : Mimics hardware by running a software client for the same purpose.
- Elastic Load Balancing : Manages load distribution among a cluster of dynamically managed servers, which grows and shrinks according to the traffic.
- Geographic : They extend range of L7 and L4 load balancers across data centers or regions. They are also known as GSLB (Global Server Load Balancers ).
Types of Load Balancing on AWS
- Classic Load Balancer : As the name suggests, it is a classic load balancer which is designed to manage traffic over a cluster of EC2 instances.
- Gateway Load Balancer : You can use Gateway Load Balancer when you need to deploy and manage a fleet of third-party virtual appliances that support GENEVE (Its a type of protocol which uses port number 6081 and limits transmission unit to 8500 bytes). These appliances enable you to improve security, compliance, and policy controls.
- Application Load Balancer (L7) : Handles multiple HTTP apps across machines. Load balancers apps on the same machine (for containers) , load balancing based on URL or based on hostname in URL. Also has a port mapping feature to redirect to a dynamic port.
- Stickiness can be enabled at target group level, the same request goes to the same instance, generated by ALB by using cookies and not at the application level.
- True IP of the client is never visible to the servers.
- Network Load Balancer (L4) : For TCP traffic , handle millions of requests per minute and are highly performant, support for both static and dynamic IPs, less latency, most commonly used for extreme performances.
Health check is done by providing a port or a route through which the instances communicate only about their health.
Some more things to know about Load Balancers
- CLB and ALB support SSL certificates and provide SSL termination.
- Stickiness means that requests from the same user goes to the same instance during a session.
- All Load Balancers have static host names , do not resolve and use underlying IP.
- Can scale but not instantaneously, it takes time for a new EC2 instance to warm up which needs to be taken under consideration when you define parameters for the condition in which an instance needs to be scaled.
- 4xx errors are client induced, 5xx errors application induced.
- 503 error defines peak capacity.