CodePark/ questions / Load balancing & proxies
START PRACTICINGPRACTICE
Backend question · System design & architecture › Load balancing & proxies

Your chat servers hold long-lived WebSocket connections, and connection counts per server vary a lot. Which load-balancing algorithm keeps load most even when new connections arrive?

Least connections

"Least connections" sends each new connection to the server with the fewest open connections. So a new or lightly loaded server fills up first, and load evens out.

"Round robin" is the tempting wrong answer. It spreads only the new connections evenly, one server after another. It ignores how many long-lived connections each server already holds, so the imbalance stays.