The Road Ahead...

by Sundarram P. V.

Friday, June 06, 2008

Five9s Availability - Is it too much to ask for?

Imagine logging into GMail, and suddenly getting a Oil change page. No way thats gonna happen now right?? Nearly 4 years back I used to see this page quite often, but over a period of time GMail has certainly matured as a product. They are still adding features seamlessly and making releases without any downtime of the service. That makes me look in awe at many services which achieve this and I sometimes wonder what it takes to achieve 99.999(Five9s) i.e. approximately 6 minutes of downtime in a year.


Message from ABC: OOPS, No donuts for you.
Developer of ABC: The possibility of this is infinitesimally small and guess what, Shit happens!!!
User: Damn!!! It always happens when I am in middle of something important
But hey why go through such a ordeal.. Let me try XYZ...

Real donuts for guessing the service ;)

Why?

For starters, if there are lot of outages users will loose trust in the service and might start looking at it as a liability. Twitter is a classic example of that. I would hate to see GMail go down while i am using it. In the Web 2.0 world there are lot of 'me too' services to take your place, the only differentiator can in many instance be speed and availability of your service.
This is normally in a later stage of a start-up as feature takes precedence over availability. But a use of little common sense initially will prolong the availability issues.

Why measure?

It is always better to measure than not to. It can be used to compare the availability of service month over month and progress made in terms of availability. In extreme cases, one can boast in some scalability and availability conference. ;)

Why Five9s and not any other number?

Six minutes of downtime is not very huge and not very small, though this depends on the type of outage and service. Choose a number that suits your goals. It is also a measure of availability of service during its business hours(24x7 for most web 2.0 startups). It is a number which is quite difficult to achieve but not impossible. Every year very few services achieve Five9s. Personally I look at it as a benchmark as only a selected few make it to this league.

The downtimes can be categorized into two, viz. predictable and unpredictable ones.

1. Unknown/Unpredictable ones
a. DB/web server needing a restart(often with windows based environs.)
b. Hardware failures

The service should have at least have two point of failures for the whole service to fail completely. It pays to have redundancy but its expensive too. RAID depending on the configuration will only protect the data, but the time required to recover from such a disaster and to go up online again will be huge. Its better to have another redundant h/w and s/w which is hot swappable. This will require a lot of design and architecture considerations. Its always better to assume that some failure like this will always happen and being prepared to tackle it. It is not financially viable for many early stage startups to have redundancy for everything, but being prepared for such a eventuality will not hurt the company.

c. A spike in traffic, taking everything down with it.
Its difficult to be prepared for spike, it is given that there will at least be one spike in a year you cant handle. Having a architecture and design for rainy days will pay off in the longer run. Services like Amazon EC2 will certainly help in handling spike, but it all depends on the preparedness for a spike.

d. Some goofy in datacenter, restarts the server by accident (I am not making it up. it has happened twice.)
To avoid such a scenario don't have your server in India, unless you are having redundant counterpart elsewhere. Not kidding!!! India is light years behind for providing any serious hosting services. If at all you want to have a server in India for various reasons, avoid resellers. If the number of servers are more go for a co-location.

continued...

Sunday, November 04, 2007

OCC Mumbai Meet

Off late I have come to notice the number of startups in India are increasing. Last Year the number of Startups could be counted, but now there is a explosion in the number of startups. Thanks mainly to Web 2.0
Here are some of the pics of OCC and Barcamp Mumbai I had visited.

Thursday, October 11, 2007

Funny!!!



I found this advertisement while reading a blog, and i found this add by google funny.....

Saturday, October 06, 2007

The First Step

September 3rd:
0825 hrs: 30 pair of eyes zeroin on a location, and are carefully calculating their next move. From the look of their eyes one could tell that they wont hesitate to kill if it is necessary. Chaos erupts as it comes to a halt and people are in a frenzy to board. With room only for a dozen, somehow all 29 of them make it. My jaws dropped, my shoulders sagged and my legs felt loose when I suddenly realised that I have to go in such a train daily to reach my office.
0855 hrs:
After watching 4 trains pass by, I summoned all the strength and courage to actually approach the train. I was pushed aside by a set of very decent looking hooligans when the next train came. After that movement, I really became one of them and any one could see the same fire in my eyes.
I finally got in and felt elevated about the herculian task I had just finished, but to my dismay I found the challenge had just began as I was standing in way of people who wanted to get down
at the next station.

October 1st:
0840 hrs: Nearly ##(couldnt count because of my concentration) pair of eyes zoomin on a location
and I made it(dont know about the rest as I was the first).

After a month, I started enjoying the whole experience. In retrospect I feel, the first step is often the most difficult and the most important one to take. Things do get easier as time goes by.

I dont know when I will be taking my first step.

Sunday, September 30, 2007

Changed Address!!!!

The idea of buying my domain had been there in the back of my mind for quite some time.
Finally I bought one and have changed the blog address from pvsun.blogspot.com to blog.pvsundarram.com.
All the old links will still work!!!!.
Looking forward to buy more in the future....

Missed it this time!!!

I went for a walk in the ground near my house, and I found lots of people working on something huge. After looking more closely, I couldnt determine what they were really trying to do. As Ganesh chathurthy was nearing, the artists were adding finishing touches to what they were doing. I could hardly believe my eyes, when I saw what they did just after 10 days. It was like a full blown ship!!!!

This photo was taken at 00:30 hrs from a distance of more than 400 meters and the place was still buzzing with people.

If you are wondering where this photo is coming from, you can check zoom.in.
Tags:

Friday, August 10, 2007

OOPS in JavaScript : Part II

In JavaScript we might not need inheritance all the time but as the applications gets complex we might need more structuring of code and also for reusing it. Inheritance according to Mozilla's documentation states that we need to copy the prototype of the base class to the Sub Class. You might ask why. The reason is 'Prototype' is nothing but the Structure of a object and this structure is shared across all the instances of the Class. When a property is added to a object dynamically, it is only for that particular object and not the whole class. On the other hand, when a property is added to the prototype, that property gets added in all the instances of that class. This might sound a little confusing, but thats the way the language works.
We will have to be very disciplined when we are writing a application partly because the language is dynamic and very flexible. We should follow some good practices while doing inheritance,
1. Avoid adding of properties to objects inside the functions dynamically(that includes the constructor) and always add them to the prototype object. In this case we might not be utilizing the full power of JavaScript, but then all the properties will not get inherited. The properties which are dynamic in nature does not get copied to its subclass.


BaseClass Definition
:
:
myFunction : function(){
this.newProperty = 0;
},
:
:

2. A very common mistake one can make is after inheriting, they replace the prototype of the subclass object.

inherit(BaseClass, SubClass);
SubClass.prototype = {
:
:
};

3. Avoid adding properties to prototype of BaseClass after inheritence, it makes the code very confusing and unreadable to others. But it will get reflected in the SubClass.

inherit(BaseClass, SubClass);
BaseClass.prototype.xyzProperty = QWER;

There are many approaches to do a extend, but it is very difficult to do a true extend in a dynamic language, because properties can be added dynamically. One should take a approach depending on the way they organize their code.
Now after knowing the donts, we will have to write our own extend function or use a function from any library you like. I am not going to re-invent the wheel(I might be taking a fairly similar approach), I will just explain the extend function of YUI.
Original Code

extend: function(subc, superc, overrides) {
if (!superc||!subc) {
throw new Error("YAHOO.lang.extend failed, please check that " +
"all dependencies are included.");
}
var F = function() {};
F.prototype=superc.prototype;
subc.prototype=new F();
subc.prototype.constructor=subc;
subc.superclass=superc.prototype;
if (superc.prototype.constructor == Object.prototype.constructor) {
superc.prototype.constructor=superc;
}

if (overrides) {
for (var i in overrides) {
subc.prototype[i]=overrides[i];
}

YAHOO.lang._IEEnumFix(subc.prototype, overrides);
}
}

After checking the arguments, they create a new dummy class. The prototype of Super Class is then copied to this dummy class. The reason being that in JavaScript everything is a reference and if the prototype of Super class is copied directly to the Sub class, then the Sub Class and the Super Class will be referring to the same prototype. This can be catastrophic. For this we will have to separate the prototype of Sub Class and the Super Class. While inheriting, we will have to call the constructor of the Super Class to initialize. Thats why they are adding a property superclass and assigning the constructor to its prototype's constructor. Apart from that, the guys at yahoo have made sure that derived object has all the enumerated functions when it is overridden(this is a problem in IE). Not only we are reusing the code, we are also reusing the research that went into building the library. And if they had not documented(comments) it in their code, it would have probably never been discovered by others.
Tags |- |
| |

After a long time.....

Finally after a month of inactivity i am back...
I couldnt manage to come online for the past one month(i dont know how I survived this) partly because i quit my job at tutorvista..
I had not at all planned it... but it happens to everyone of us all the time...
Now my mind is vascillating between working in a startup and start something on my own...
Tags |- |
| |

Tuesday, July 03, 2007

OOPS in JavaScript : Part I

Every one of us knowingly or unknowingly uses OOPS in JavaScript. Every function and every global variable we add in the script is actually a property of window object. The DOM API is also a very powerful API which we extensively use. There are no Classes( in actual sense ) in JavaScript.
But first one should understand why we go for OOPS, two of the main reasons i see are code maintainability and extendability. For instance YUI Library is extensively used by many big sites, the code is getting reused everywhere and libraries like the yui-ext are extending it and taking it to the next level. And thats power... General developer mentality is "i'll do it myself"... Its very natural, but has its side effects of reinventing the wheel again and if we are going to take the same approach i don't think there is a point in reinventing it.... Better would be extend the code that is already there( should be well written and extendable ;-) ) and take it to the next level...
OOPS is intended for greater flexibility and maintainability, that IMO is achievable in JavaScript.

Classes
There are no classes in real sense of the word in JavaScript. Every function, every property( except the native ones like number, string... ) are objects. Any function can be a constructor to the class. All functions are a instance of Function.


/**
* @class MyClasss
* @constructor
* This is my class constructor
* @param {Object} argument1 first argument for configuring properties of the objects
*/
function MyClass (argument1)
{
//some constructor code
this._config = argument1 || {};
}

The properties to the object can be added in run-time. The prototype property determines the initial structure of the object( thats why they call it prototype and it is a property of Function ). But it is a good practice to define all the properties that will be used in the prototype object. Which can be added like this

/**
* @method MyClass
* this is my first method
*/
MyClass.prototype.myFunction = function () {
alert('hello world');
};
/**
* @type String
* @property name
* name of the instance
*/
MyClass.prototype.name = '';
/**
* @private
* @type Object
* @property _config
* configuration object
*/
MyClass.prototype._config = null; //default value

Here if you notice it is practice and not a must because properties to the objects can be added on the fly thats why all the objects are unique and thats why there are no classes in JavaScript. If you see the above code, the property _config is marked private but it is not actually private. In JavaScript there are no scopes for properties of objects. To put it differently all properties of an object are public.
Whatever has been done so far is just for making the code extendable. There are other approaches to OOP like

var myObj = {}; // one way to create a new instance
//adding method to the object
myObj.myFunction = function () {
alert('hello world');
};

But the biggest problem with the above approach is it is not extendable.
One can also add static properties to the class.

/**
* @method MyClass
* my static method
* @static
*/
MyClass.myStaticFunction = function () {
alert('my static function');
};

If you notice closely we are not adding this property to the prototype object but we are adding to the 'MyClass' itself. This is shared across all the instances of the MyClass. The use of 'this' in static methods will refer to MyClass and not the instance and also reference to any other static property via 'this' is not possible. Now that we have created a class-like structure we can now create instances of the MyClass.
var myObj = new MyClass(); //creating a new instance.

The 'new' operator creates a new object with the structure of MyClass.prototype and then calls its constructor viz. MyClass. The constructor does some initialization and the object is returned to myObj. In JavaScript objects are passed by reference. Here i am not passing the parameter in the constructor. It is not mandatory to pass the required arguments to any function( including constructor ). The memory will not get released if there are any references to that object.
If you notice carefully we are actually adding properties to the prototype object on the fly. You can access the properties of 'myObj'.
myObj.myFunction();

Tags -

___