# What is a Load Balancer?

### Introduction

A load balancer is a crucial component in a distributed computing as it distributes the incoming load across multiple servers. The primary purpose of load balancer is to ensure that a single server does not get flooded with multiple requests, preventing downtime and performance degradation.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705424573071/98937953-eff7-44a9-b7cc-b92f764e7ece.png align="center")

### How Load Balancers Work?

1. When a user sends a request to access a website or an application, the request first reaches the load balancer.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705426001566/824245f5-88b4-4ba3-a96b-a2883402612a.png align="center")
    
2. The load balancer manages a pool of servers aka nodes capable of handling the incoming requests. These servers host the application or website.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705426016011/3820ba85-dab3-4214-95bd-c943c37f5f71.png align="center")
    
3. The load balancer uses a specific algorithm to decide which server from the pool should handle the incoming request.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705426404328/f1b2c6c5-f4ed-408b-ab1c-01e42aa750ab.png align="center")
    
4. The selected server is then assigned the task of fulfilling the user request and load balancer forwards the request to the chosen server.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705426537988/be239920-1999-47a7-9c14-5cad3bb6680b.png align="center")
    
5. The selected server processes and generates a response and sends it back to the user through the load balancer.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1705426622868/18d9d496-6741-4fa3-8a15-3e3307fc36f3.png align="center")
    

### Types of Load Balancer

1. **Physical Load Balancer:** Physical devices dedicated to balancing traffic. They often provide high performance.
    
2. **Software Load Balancer:** Implemented as software solutions and can be run on standard server hardware. These are easier to scale than physical load balancer.
    
3. **Layer 4(Transport Layer) Load Balancer:** Operates at the transport layer of the OSI Model and makes decision based on the network-level information such as IP addresses and ports. It just acts like a firewall.
    
4. **Layer 7(Application Layer) Load Balancer:** Operates at the application layer of the OSI Model and makes routing decision based on the content which allows for more advanced load balancing decisions.
    

### Load Balancing Algorithms

1. **Round Robin:** Distributes load equally among all the available servers. Each server gets a turn to handle a request.
    
2. **Least Connection:** Directs the traffic to the server with the least active connections. This helps loads more evenly.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1706647487011/96785352-4e0a-4554-82ef-99a023476901.png align="center")
    
3. **Least Response Time:** Directs the traffic to the server with the least response time. This can help minimize latency.
    
4. **IP Hash:** Uses a hash of client's IP address to determine which server will handle the request. This ensures that request from the same IP address always go to the same server.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1706647502617/b9100758-dc05-42f7-8723-de0593806c75.png align="center")
    
5. **Random:** Select a random server to handle each request but it may not guarantee an even distribution of load.
    
6. **Weighted Round Robin:** Similar to Round Robin, but servers are assigned weights. More the weight more will be the requests handle by it.
    
7. **Weighted Least Connections:** Similar to Least Connection, but servers are assigned weights. More the weight less will be the requests handled by it.
    
8. **Adaptive Load Balancing:** Adjusts the load balancing algorithm based on the server's load or performance.
    

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Follow For More !</div>
</div>
