Monday, August 31, 2009

How to do stateful Registration In Windows Azure when using multi instances

Microsoft Windows Azure cloud enable you to horizontally scale out your application by modified the number of instance on the fly, and the fabric controller will handler the load balance for you.

But one issue is that, u cant do stateful application for this kind of scale.

For example, user login.
Normally the way we do login is that. Once the user has been successfully login, we put some of the data into session, so that our application will know the user has been login within the time out duration.

ISSUE
However, when multi-instance running the same piece of application, if you store info in one of those instances, the other instance wouldn`t be aware of the user has been login.

Below is the work around for using multi-instances.


What i am going to do is that,

Web Roles:
Every time a web role receive one request, check whether there is a login record in the table storage, if the data existed (e.g we can use the userid for RowID, if the userid existed), then see the lable "expired" for every row,

if it is false, which mean the user has already login, update the label "last_visit"
otherwise, hasn`t login, direct to login page.
after successful login, create one entry in the table.


Worker Role:
Schedule tasks to check the session table, see whether "current_time" - "last_visit" > time out
if true, set "expired" to true, otherwise set to false.


Concerned
1) Data consistency
Data might updated by one instance, but when another instance call for the same piece of data, that data might not be updated, maybe still getting the old value.

2) Too much over head

Conclusion:
I think this approach is doable.

For consistency, even the value we read is the old value, which mean the time out wouldn`t be the exact time as we specify. Maybe it will be a bit larger or smaller then the expected value.

For over head. There is something we need to compromise, in order to have horizontal scalability.


How about other Cloud
:

I only want to talk about Google App Engine here, coz gogrid or amazon web service, there are more likely offer "vertical scale out".

In Google App Engine, they already offer user the MEM-Cache, which can be shared by all the instances. And the access time or speed is fast.

Which mean it would be easy and simple to implement my approach in Google App Engine.
And we won`t has the two concerns as well.

No comments:

Post a Comment