algorithmload-balancing

Best load balancing algorithm to distribute requests across a group of servers?


Which is the better load balancing algorithm to distribute incoming requests across a group of servers? I've read that they are some algorithms like Round Robin.. but I'd like to know your opinions about which is the better or at least most used algorithm for this.

Hope you guys can help me.


Solution

  • The answer is: it depends. the best load balancing is achieved when considering multiple factors which are specific to the service. For example, say you have a service which provides an API to encode a string, where the encoding depends purely on the content of the string. You have N replicas of the service running.

    One simple approach would be to simply have a client pick service index i = hash(string)/N. Assuming that the input string are uniformily distributed on the hashing space, this will work well and is very easy to implement.

    Say now for some reason that for some reason the strings are not well distributed on the hashing space (maybe a lot of string may be repeated, for example). In this case you could use a simple approach of doing round-robin, or randomly selecting an index. You could also have a measure of back pressure from the servers: for example, if an RPC call is synchronous, you could measure at the client side how long it takes and, in the case of string encoding, divide that by the length of the string; if a client notices this number going up, it probably means the service is not being able to keep up and the client could reduce the traffic it sends to such client. This is obviously a little more complex.

    TLDR: There are many options for load balancing, which one is "the best"depends on the specific nature of the problem being scaled.