What is load balancer and how it works?

Load balancer

Load balancing means efficiently distributing incoming traffic across a group of backend servers.

A load balancer sits in front of backend servers and manages incoming requests to maximize speed and capacity utilization. It ensures that no one server is overworked.

If a single server goes down, the load balancer redirects traffic to the remaining online servers. When a new server is added to the group, the load balancer automatically starts to send requests to the newly added server.

A load balancer has following 3 main tasks:

  • Distributes incomind requests efficiently across multiple active servers
  • Ensures high availability by sending requests to active servers
  • Provides the flexibility to add or subtract servers as needed

load balancer

Benefits of load balancing

  • Reduced downtime
  • Scalable
  • Redundancy
  • Flexibility
  • Efficiency

Algorithms load balancer uses:

The different load balancer uses different algorithms. Following are some most commonly used load balancing algorithms:

Round Robin

Requests are distributed across the group of servers sequentially.

Least Connections

A new request is sent to the server with the fewest current connections to clients. The relative computing capacity of each server is factored into determining which one has the least connections.

Least Time

Sends requests to the server selected by a formula that combines the fastest response time and fewest active connections.

Hash

Distributes requests based on a key we define, such as the client IP address or the request URL.

IP Hash

The IP address of the client is used to determine which server receives the request.