The Wayback Machine - https://web.archive.org/web/20261105174524/https://www.geeksforgeeks.org/system-design/load-balancing-algorithms/

Load Balancing Algorithms

Last Updated : 19 Oct, 2026

A load balancer distributes incoming traffic across multiple backend servers. Load-balancing algorithms determine how each request or connection is assigned to an available server.

  • Help distribute workload across multiple servers.
  • Reduce the risk of individual servers becoming overloaded.
  • Can improve performance, scalability, and availability when combined with proper health checks and redundancy.

Example: During a high-traffic sale, an e-commerce application can use a load-balancing algorithm to distribute incoming requests across multiple application servers.

Types of Load Balancing Algorithms

Load-balancing algorithms can generally be classified as:

load_balancing_algo

Static Load Balancing Algorithms

Static algorithms distribute requests according to predetermined rules. They are usually simpler to configure and work well when backend servers have predictable workloads and similar characteristics.

1. Round Robin

Round Robin distributes requests sequentially across available servers.

For three servers:

Request 1 -> Server A
Request 2 -> Server B
Request 3 -> Server C
Request 4 -> Server A

Advantages

  • Simple to implement.
  • Requires little runtime load information.
  • Works well when servers have similar capacity.

Limitations

  • Does not consider current server workload.
  • Long-running requests can cause uneven resource usage.

2. Weighted Round Robin

Weighted Round Robin assigns each server a weight based on its expected capacity. Servers with higher weights receive a larger proportion of incoming requests.

Example: If Server A has twice the capacity of Server B, it may be assigned a higher weight and receive more traffic.

Advantages

  • Suitable for backend servers with different capacities.
  • More flexible than basic Round Robin.

Limitations

  • Weights are usually configured in advance.
  • Does not inherently adapt to sudden runtime load changes.

3. Source IP Hash

Source IP Hash selects a backend server by applying a hash function to the client's IP address.

  • Requests from the same source IP generally map to the same backend while the server pool and hash configuration remain unchanged.
  • Can provide a basic form of session affinity.

Advantages

  • Can keep requests from a client mapped to the same server.
  • Does not require a separate session cookie for basic affinity.

Limitations

  • Changes to the server pool can change mappings.
  • Multiple users behind the same public IP may be routed to the same backend.
  • Traffic distribution may become uneven.

Dynamic Load Balancing Algorithms

Dynamic algorithms select servers using current or recent runtime information.

They can adapt more effectively to changing workloads but require additional monitoring and processing.

1. Least Connections

Least Connections sends a new request or connection to the server with the fewest active connections.

Advantages

  • Useful when connection durations vary significantly.
  • Can distribute active connection load more effectively than Round Robin.

Limitations

  • Requires continuous connection tracking.
  • Number of connections may not always accurately represent actual server resource usage.

2. Least Response Time

Least Response Time selects a backend using observed response-time information and, depending on the implementation, may also consider active connections or other metrics.

Advantages

  • Can favor healthier and faster-responding servers.
  • Useful for latency-sensitive workloads.

Limitations

  • Requires continuous performance measurements.
  • Short-term latency variation may affect routing decisions.

3. Resource-Based Load Balancing

Resource-based load balancing selects servers according to metrics such as:

  • CPU utilization
  • Memory usage
  • Network bandwidth
  • Queue length
  • Other application-specific health metrics

Advantages

  • Adapts routing decisions to current resource availability.
  • Can help reduce overload on busy servers.

Limitations

  • Requires frequent collection of server metrics.
  • More complex to implement and operate.
  • Stale metrics can result in suboptimal routing decisions.

Factors Affecting Algorithm Selection

Selecting the right load-balancing algorithm depends on workload characteristics, server capacity, and performance requirements. Key factors include:

  • Traffic Patterns: Steady workloads may suit static algorithms, while fluctuating traffic may benefit from dynamic routing.
  • Server Capacity: Servers with different capacities may require weighted traffic distribution.
  • Connection Duration: Long-lived connections may benefit from Least Connections.
  • Session Requirements: Applications requiring client affinity may use IP hashing or session persistence.
  • Latency Requirements: Response-time-aware algorithms can help optimize latency-sensitive applications.
  • Runtime Metrics: Dynamic algorithms require accurate and up-to-date monitoring data.
  • Operational Complexity: Adaptive algorithms generally require additional configuration and monitoring.

Selecting the Appropriate Load Balancing Algorithm

Different algorithms are suitable for different workloads and infrastructure requirements.

  • Round Robin: Suitable for servers with similar capacities and relatively uniform request-processing requirements.
  • Weighted Round Robin: Suitable for servers with different capacities that require proportional traffic distribution.
  • Source IP Hash: Useful when basic client-to-server affinity is required.
  • Least Connections: Suitable when connection durations vary and active connections need balanced distribution.
  • Least Response Time: Useful for latency-sensitive workloads with reliable response-time measurements.
  • Resource-Based: Suitable when server resource utilization varies and accurate runtime metrics are available.

Common Use Cases

Load-balancing algorithms are used in applications that require efficient traffic distribution across backend servers.

  • E-commerce Applications: Distribute requests during sales and traffic spikes.
  • Web Applications: Balance HTTP requests across multiple application servers.
  • Streaming Platforms: Distribute streaming connections and media-processing workloads.
  • Microservices: Route requests across multiple instances of individual services.
Comment

Explore