Saturday, September 17, 2011

Crisps abt Scalability

Hi all, It was a great day with "Cassandra - Definitive Guide". The best thing i liked abt that book is the way they explained scalability(ofcourse abt Cassandra too :P). 
So, 
What is scalability?
It is nothing but yet another performance measure. To be clear, it is the measure on how well the application you built performs, if you add more resource to the environment it operates on. Ex. Adding more cores to processor, Increasing main memory's size, etc.,
Why should I care abt it?
Because it is not true that if you add more resource, performance of your system(ur app) should increase. Also there is a probability that performance of your system to decrease.
Can You Explain more in detail?
Yes, For sure. Actually there are two ways you can scale the processing environment.Horizontally and Vertically. Horizontally refers to adding more systems instead enhancing the existing system. Ex: Adding more web servers to serve the requests and using a load balancer ahead. Vertically refers to enhancing the existing system. Ex: Moving from 2GB ram to 64 GB ram, 16 core processor etc. 
What are the limitations?
Perfect question. The problem with vertical scalability is limitation and cost. Means how much can u extend the cores and main memory?? There is a limit for that always. And also cost is directly proportional to the square of configuration you expect. So, next horizontal scaling. The only issue with horizontal scaling[Distributed Systems] is maintenance. I'll explain with a scenario. Assume before scaling u had only one web server handling all the requests hitting your system. So, U need not worry abt consistency of data. Coz every one is going to read from the same. Now You had replicated your content and hosted one more web server to handle the traffic. So, part of your traffic reads from server 1 and another from server 2. So, now comes the problem. If you update one letter in a word in one of the pages of your web application you need to sync the same across all the web servers. There is a mega issue if the server you replicated is a database server instead a web server. I hope you understand the seriousness of the latter(database server).
Seriousness?? What Seriousness??
 Cool. Im there again :) Regarding your web server it serves static or dynamic content. Where does this dynamicity comes from?? It is because of  the data store behind it. So, once again a scenario. You have a system implements a shopping cart. Now you have 2 customers viewing the status of a same product. The best part of it is, when C1 gets data from DB Server 1 and C2 gets data from DB Server 2. Now comes the question what is the issue in that?? Let us make it more serious, the product they wish to buy has only one piece left. So, If both gets access from same server there is no issue. Who ever ordered first, based on the timestamp the conflict of their order ll be resolved and the other ll be given proper status of unavailability. But here the issue is different they both contact two different servers. Sooooooooooooooo how ll consistency be achieved :(
OOOOOOOPs what should we do then?
 There are two different solutions based on the application. One is master slave architecture and another is sharding or shared nothing architecture. 
What are they? 
 Wait for part 2.