
Example of an unpredictable server breakdown [source: Google]
As per the statistics, around 44% of industrial downtime is caused due to server failures. Do you know how it financially impacts an organisation? Well, according to a survey by IDC in 2014, an average cost of server failure is $100k per hour. Large e-commerce companies bear loss of billion dollars due to unplanned database failures in their organisation. But wait! Is it just the financial loss that they need to deal with? Apparently, No. There is more than just revenue, most importantly, a company’s customer base goes down which in turn impacts the performance.

Actual Consequences of server crashes
In such scenario, it becomes really crucial for big e-commerce giants in the market (like Amazon) to implement a reliable mechanism for efficient replication of data across its servers, and make sure they are synchronized in a timely fashion. By making the data available across multiple nodes, if unfortunately, any of the data server crashes , we simply replace it with one of its replicated model ensuring its user be oblivious to any such breakdown. Sounds simple, Right? Well, lets decide how simple it is, in the next segment. 🙂
How to handle unpredicted failures?
When it comes to commercial database networking infrastructure for big tech companies, it becomes even more challenging to design a model that helps in achieving the goal. Countless strategies are available in the market right now and looking into each will simply be beyond the scope of this blog! However, there is one simple and elegant method that we can discuss here : Consistent Hashing . It provides a straight-forward technique for data partitioning and replication over clustered nodes in a complex network. Consistent hashing is based on a mechanism to dynamically distribute the data load over storage hosts.
Lets dive a little deeper and see how it works.
In the circular network , each host is assigned a key representing its position on the network which is mapped through a hash function. The hash function generates a key that corresponds to a specific node in the network (As illustrated in the Figure 3 below) . This hash function is chosen in such a way that its output range is defined in a fixed circular space or “ring” i.e. the largest hash value wraps around to the smallest hash value. For example as shown, if the hash function has range [1, 60] , then the last element 60, will point to 1 (which belongs to first node, A). Each data item identified by a key is assigned to a node by hashing the data item’s key to yield its position on the ring, and then walking the ring clockwise to find the first node with a position larger than the item’s position. Thus, each node becomes responsible for the region in the ring between itself and its predecessor node on the ring. Here for example, node A is responsible for keys mapped between F and A.

Figure 3: Clustered Network “ring” in Commercial Database Systems
Now, although sequential, but the keys assigned to each node is randomly decided, hence the key range might be skewed and it might lead to a non-uniform data distribution among the nodes. This can result in busy nodes being busier and idle nodes sitting as idle as ever. Hmm… seems like we have a problem!
Well, its time we introduce another concept : Virtual Nodes. Basically, Instead of assigning one node to a single point in the network, each node is assigned to multiple points. Hence, virtual nodes actually look like single node in the system but are responsible for more than one virtual nodes. Similarly, for data replication, we choose N-1 successor nodes. And the list of nodes it is responsible for is what we refer to as preference list. Apparently, for each node, its N-1 successor nodes will store a copy of its data and those successor nodes are listed in its preference list.
For a simpler visualization, lets take a hypothetical example. We correlate our clustered network ring with an arrangement in a bank which receives loan application requests at a huge rate. Assume the bank has S banking officials (treated as nodes) seated in a circular arrangement, shown in Figure 3. Each official has a unique ID associated with him. The system uses a mechanism to map each loan application number to generate an ID and sends it to official with the corresponding ID, for processing. Lets say, as per the banking policy, any official has to share a copy of all of his loan application requests with N-1 successively seated officials, mentioned in his preference list. For example, if N=4 , Official B shares its info with C,D and E (B has them in his preference list). This ensures data from B is replicated across 3 other nodes.
Sounds weird! why are we sharing information in a bank? Lets just say they are considered to be trusted officials (same as nodes) and there are several advantages for doing the same. We further explore few benefits of replicating the data in this manner.
Surviving data server crashes was never so easy!
The principle advantage of this methodology is that departure or arrival of a node only affects its immediate neighbors and other nodes remain unaffected. Also, this system offers an incredible method for handling server failures. Suppose that a node B is unavailable, i.e the banking official seated at B is on leave and one of his customers appears asking for his loan status. Any of the N-1 officials who are there on his preference list can be contacted for the same. The load handled by this guy on leave is evenly dispersed across the remaining available officials in his virtual network.

Figure 4: Server Crash handled in clustered “ring” network
Scaling up and down without hassle!
When a node becomes available again, or say an employee reappears after a long break , he receives roughly an equivalent amount of workload from each of the other available officials in his network . The N-1 nodes who have the key (ID) of newly added node will replicate data, maintaining a uniform balance for the network.
Its good to have flexibility!
Based on a company’s capacity and accounting for heterogeneity in its physical infrastructure, this method allows an organisation to actually decide the number of nodes (N) that are responsible to be in a virtual network. Higher replication will ensure better availability and fault-tolerance. Analogously, every bank has the authority to decide the limit on the number of members an official gets to choose to share his load with. Higher the group number lesser the pressure! 😉
Arriving at a conclusion…
We saw how incredibly this system works for busy commercial platforms by elegantly distributing the load uniformly across the network, thus preventing potential downtime. However, as people say, nothing comes without a price! This method has its drawbacks too. For example, if a new member joins, the keys in between the nodes are required to be re-computed which is non-trivial task for a commercial platform, also the basic algorithm is oblivious to the heterogeneity in the performance of nodes.
However, apart from them, this technique is very popular among the e-commerce platforms because of its simplicity and elegance. A major industrial use case is Amazon AWS (DynamoDB) which employs consistent hashing for data replication across its servers and claims to provide an exceptional availability of 99.9% on an average. Others who used this method to ensure scalability and availability are Memcached, Cassandra, and Riak. In case of sudden breakdowns , we obviously cannot go back in time and fix issues to minimize the loss, but its no harm in planning early and building an efficient failure management system while hoping for the best to happen!

Source: Google Photos
Thanks for Reading!
References
- G. DeCandia , D. Hastorun , M. Jampani , G. Kakulapati , A. Lakshman , A. Pilchin , S. Sivasubramanian , P.Vosshall , W. Vogels, Dynamo: amazon’s highly available key-value store, Proceedings of twenty-first ACM SIGOPS symposium on Operating systems principles, October 14-17, 2007, Stevenson, Washington, USA
- Online resources: https://www.youtube.com/watch?v=0X2PDMFLflY
