Open In App

Load Balancing through Subsets in Distributed System

Improve
Improve
Like Article
Like
Save
Share
Report

Before diving into what is subsetting in load balancing, we should first understand what is load balancing, and why subsetting is all the more important in load balancing.

Load balancing is the process of distributing incoming network traffic/workload across multiple servers or nodes in a network system. The main aim of load balancing is to optimize resource utilization, maximize throughput and minimize response time (overload) on any single server or resource.

What is Subset Load Balancing?

As the name itself suggests, subset load balancing partitions the system of available nodes into multiple subsets and distributes the workload among smaller subsets of resources. This is required as it helps the system to handle more traffic, reduce response times, and increase the reliability and fault tolerance of the system. Thus, using subsets, enhances resource availability and scalability as well, by reducing overall latency.

The key concept pillars related to Subsetting in Load Balancing are:

  • Partitioning: Partitioning involves breaking down the data or workload into subsets. Partitioning can be done in various ways, including hash-based partitioning, range-based partitioning, and list-based partitioning.
  • Load Balancing or Distribution of Traffic: It involves assigning the subsets to different nodes in the system to distribute the workload evenly. Load balancing can be achieved using various algorithms, including round-robin, weighted round-robin, least connections, and IP hash.
  • Failover: Failover involves ensuring that if one node in the system fails, the workload assigned to that node is transferred to another node in the system. Failover can be achieved using various techniques, including active-passive failover, active-active failover, and hot standby.
  • Monitoring: Monitoring involves tracking the performance of the nodes in the system and taking corrective action if necessary. Monitoring can be achieved using various tools, including Nagios, Zabbix, and Prometheus.

How does Hashing help in Subset Load Balancing?

Hashing is a technique or process of mapping keys and values into the hash table by using a hash function. It is done for faster access to elements. The efficiency of mapping depends on the efficiency of the hash function used.

A hash function is described as a function that maps one piece of data as in a structure or object, to a different kind of long integer value(eg: SHA256), which is considered as the generated hash code. One possible way to implement hashing is using Hash Tables or Hash Maps.

Hash Tables

To build such a hash table, we need to build an array for all possible indices, but it would be practically impossible as the output range of a good hash function would be in the range of 32 or 64 bits. To overcome this, we need to have a reasonably sized array, like, 

index = hash_func(object) % N

Secondly, another problem that we may face is this object hashes will not be unique, and there would be many such collisions, and therefore simple direct index will not work. Ways to handle this would be to assign a bucket of values for each index. Thus, to add a new object, we need to calculate its index, and we need to check if it already exists, if not, add it. Thus, with this structure, although the searches within buckets are linear, a properly sized hash table should have a reasonably small number of objects per bucket, which would eventually result in almost constant time access ~ O(N/K), where K is the number of buckets and N is the total indexes in the array.

Designing on a larger scale: Distributed Hashing

Scaling out is a technique that involves adding more nodes to the system to increase its capacity. 

Distributed hashing is a load-balancing technique that involves partitioning the data based on its hash value. Sometimes it is necessary or desirable to split a hash table into several parts, hosted by different servers. Each node in the system is responsible for a range of hash values, and the data with the corresponding hash value is assigned to that node. One reason to do such is to bypass the memory limitations in a single computer, thus giving way for the construction of arbitrarily large hash tables, which will go hand-in-hand with enough servers.

Example:

Here is an example of distributed hashing with proper tables:

Suppose we have four nodes or servers in our system and want to partition the data based on its hash value. We can use the following table to map the hash values to the nodes:

Node Range of Hash Values:

1 0 – 25
2 26 – 50
3 51 – 70
76 – 100

Suppose we have a data item with a hash value of 35. According to the table, this data item should be assigned to node 2. Similarly, a data item with a hash value of 85 should be assigned to node 4.

Distributed hashing with proper tables ensures that the workload is distributed evenly across all the nodes in the system. It also ensures that each node is responsible for a specific range of hash values, which makes it easier to manage the system.

Why Distributed Hashing fail in case of a variable number of servers?

Distributed hashing seems easy to implement and intuitive and works quite well until the number of servers changes. Suppose, one of the servers becomes unavailable or crashes or maybe we decide to add another server. Thus the hash distribution would change then, for the change in the number of nodes. This may very well lead to degrading performance.

Consistent Hashing – A Complete Solution:

One distribution scheme which doesn’t depend on the number of servers is Consistent Hashing.

Consistent hashing is a load-balancing algorithm that can be used to implement subsetting. It involves mapping each server to a point on a circle or hash ring, with the circle representing the range of all possible hash values. Requests are then mapped to a point on the circle based on their hash value. The server responsible for handling the request is the server located immediately clockwise from the request’s point on the circle.

Consistent hashing has several advantages over other load-balancing algorithms. Some of them listed below:

  • Scalability: It is highly scalable, as the addition or removal of a server only affects a small subset of the total workload.
  • Fault Tolerance: It is also fault-tolerant, as the removal of a server only affects the subset of the workload that was handled by that server. 
  • Handling Uneven Distributed Workloads: Additionally, consistent hashing can handle unevenly distributed workloads by partitioning the circle into multiple virtual nodes for each server, which can balance the workload across multiple servers.

Example of how consistent hashing solves the problem of distributing requests to servers in case of adding or removing of servers.


Last Updated : 15 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads