Load Balancing

Read this post to know why load balancing is required. 

Load balancing is evenly distributing the 'N' number of requests to multiple servers to reduce the burden of a single server. 

The client usually sends randomly a number which is called request ID while sending a message. Take the request ID (request_1) and hash it which will produce a particular number (result). This resultant number can be mapped to a specific server. 

                        h (request_1)    =  result 

                        server_no  = result % no_of_servers




If the client (Android) sends a request to the server, it will be hashed and the result will be processed to find the particular server at the load balancer. 

For example, consider the number of servers is 3 such as servers 0, 1, 2. If the result for request-id (10) is 3, 3 % 3 is 0. So, this request 10 will be sent to server 0. If the result for the request-id (40) is 11, 11 % 3 is 2. So, this request 40 will be sent to server 1.  


Each server can handle the 'X/N' number of loads, in this way we will evenly distribute random requests.  If there are X requests, each server would handle 'X/no of servers' requests. 

If the customers are happy with our servers, they might hit our servers a lot. In this case, we need to add more servers. For example, if we have 2 additional servers, now the request-id 10 should be sent to server 3. Similarly, request-id 40 will be sent to server 1. 



After adding two more servers, each server will lose few loads from its bucket to get equal distribution of requests. 

If the hash function is the same, the function will be sent to the same server. If it reaches the same server (for example to access the database), we can store this information in the local cache of the server. But when the whole system changes, hashing will not work. So, we will go for consistent hashing. 

Read Caching next.

References: Gaurav Sen Youtube Channel

Comments