Scalability and availability are two important characteristics of any enterprise application that we build. Load balancing and fail over helps in achieving these two characteristics. Let us first try to understand these terms with the help of some real life example and then try to understand how we use them in computer world. Lets take the example of a queue at any multiplex, assume that there is just one queue and there are lets say 4 counters. At the beginning of the queue is a staff from the multiplex whose job is to direct the next person from the queue to any of the four available counters. The four counters here present the members of a cluster, the staff who redirects the next person in the queue to any of the available counter plays the role of the loadbalancer. Now lets further assume that the computer at any of the counter stops working. In such a scenario the current counter that is servicing the request should be able to re-direct this request to the other counter which is functioning properly and start functioning again when the computer starts functioning. This is what we call failover in computer world. Imagine the situation if there had been just one counter and there was a big queue. The response time would have been very slow and to make the matter worst what would have happened if the only available counter's computer stops working.
Scalability is an application's ability to scale it up with the growing number of users or demand. Let us suppose that we set the response time for a particular page to be 5ns. With the number of users growing, the performance is bound to degrade as the application server might get jammed as it has limited number of resources. To overcome this situation and to maintain the same performance level an application should be able to scalable itself up. An application should be able to add more resources to achieve the same same performance level. It can be done by adding more RAM or increasing the number of CPU but these have certain limitations. The best solution is to add more number of servers so that instead of the request being processed one at a time we can process more than one request at the same time. As many numbers of request can be processed simultaneously as many servers we have. We add more than one server and create a cluster and make the load balancer aware of the cluster. It is the responsibility of the Load Balancer to re-direct the request to any of the servers in the cluster based on the algorithm that we have selected (Random,RoundRobing, etc). If any of the server in the cluster fails the request should be able to failover to any of the available server in the cluster. In this way the application becomes highly available even if some servers fail as the application can failover to the availabe servers in the cluster. Scalability and availability are the characteristics which should be addressed at the design time only because its not possible to add them once the application is build and even if its possible its very difficult once the application is build. In case of failover the communication between servers happens through RMI to pass information from one server to another server and for RMI to take place its important that the domain objects are serializable.
We achieve these two characteristics through clustering with some care taken at the time of designing the application. Clustering can be either vertical, horizontal or hybrid. In vertical clustering all the servers in the cluster reside on the same physical machine. Although its the simplest of all the cluster its drawback is that in case the physical machine on which the cluster resides goes down, the whole cluster goes down and the application stops responding to user request. In horizontal clustering the servers of the cluster reside on two or more than two different physical machine so that even if one machine goes down the servers in that are on the other machine of the cluster still continue working and the fact that some of the servers are down is not transparent to the user of the application. This is more reliable than vertical clustering as only in the case of both the physical machine going down application stops responding. The hybrid clustering is the mixture of both vertical and horizontal clustering where some of the servers in the cluster reside on the same physical machine while others reside on some other physical machine. Horizontal clustering is the most common in production environment.
This was my attempt to explain clustering,load balancing and fail over in simplest possible way. In my next blog I will explain the same concept through code example by creating a cluster and using a loadbalancer.
Thanks for reading.
No comments:
Post a Comment