MongoDB

Load Balancing Algorithms Explained

Explore Round Robin, Least Connections, IP Hash, and Weighted load balancing algorithms with real-world system design use cases.

S

srikanthtelkalapally888@gmail.com

Load Balancing Algorithms Explained

A load balancer distributes incoming traffic across multiple servers to ensure no single server is overwhelmed.

Why Load Balancing?

  • Prevents single point of failure
  • Enables horizontal scaling
  • Improves response times
  • Allows rolling deployments

Algorithms

Round Robin

Requests distributed sequentially across servers.

Request 1 → Server A
Request 2 → Server B
Request 3 → Server C
Request 4 → Server A

Best for: Servers with equal capacity.

Weighted Round Robin

Servers get traffic proportional to their weight.

Server A (weight=3): 60% traffic
Server B (weight=2): 40% traffic

Least Connections

Route to server with fewest active connections.

Best for: Long-lived connections (WebSockets).

IP Hash

Hash client IP to pick server — ensures session stickiness.

Best for: Stateful applications.

Random

Random server selection — simple but can cause imbalance.

Layer 4 vs Layer 7

  • L4: Routes based on TCP/IP (fast, no content inspection)
  • L7: Routes based on HTTP headers/URLs (smart routing)

Health Checks

Load balancers ping backends every 10s. Failed servers removed from rotation.

Conclusion

Least Connections for dynamic workloads, Round Robin for stateless services, IP Hash for sticky sessions.

Share this article