Sunday, 2 November 2008

Windows Azure - Cost Efficient Code Reviews

So with the advent of Windows Azure, I see that companies will put more stress on Code Reviews.

This is a great thing for companies in general as I do believe that not enough companies invest enough time in Code Reviews.

So why do i believe that Windows Azure will invest more in Code Reviews? I believe this because without code reviews, badly written applications could cost companies a lot of money than a well written application

Reviewing for Cost Efficiency

I suspect a new set of best practices and patterns will emerge with the ultimate aim of keeping costs low for applications. I suspect we will also see the development of new tools which will allow you to simulate loads and predict the cost of applications.

In order to keep cost efficiency companies will require team leads to review code with a particular emphasis on cost.

Code Reviews will be looking for:

  • Unnecessary use of SQL Services (which has a higher cost than Windows Azure Storage)
  • Appropriate use of caching (rather than just retrieving from the storage area blindly)
  • etc, etc

Session State Example

A good example of where you can use unnecessary costs in a web application is the session state.

An ASP.NET application on each HTTP Request will retrieve the session for the current user. In a normal world this is not a big deal because we have already paid for our session state. I say we have already paid for our session state, as we either have an inprocess session, or a sql server session. There is no real cost for maintaining our session, the infrastructure is already there. We have paid for our SQL Database and we tend not to be charged by hosting companies for internal network bandwidth usage.

In a world of Azure we cannot use InSession providers, because we cannot rely that requests will always be serviced by the same server / VM. Therefore we must keep session in Windows Azure storage (you could keep it in SQL Services but that would just frankly be frivolous). This is the only way (at present) we can guarantee to keep our session data with scale.

The downside is that everytime we retrieve data from the session, it's costing us money (Microsoft has not released its pricing model, so we don't know how much yet). So we therefore we have a few considerations?

Does the page in question use the session?

If not switch it off for that page, this is a performance best practice anyways but one which is generally ignored. If you switch off the session for that page then you are potentially saving yourself bandwidth, storage, CPU costs (depending on Microsoft's pricing model).

Is it appropriate to keep the data in the session?

Lets say there is a piece of data that is potentially accessed by the user in the course of a session but it may or not be used? Is it appropriate to keep that bit of data in the session (especially if it's quite large)? To be honest that question that sort of question is still valid for todays applications but with a utilization cost model, it massively increases the importance of such questions?


Anyways this is just my rambling as I am sitting in an airport in Los Angeles, however i think these sort of questions will become very important in a world of Windows Azure.

Developers be prepared to optimize applications not just for performance but now for cost.

It will be interesting to see the guidelines, best practices and tools that get developed in this area.

1 comment:

Jason Cohen said...

There's no doubt code reviews turn up bugs. Your examples of session state are good because it's easy to introduce bugs and hard to "prove" the code is right through other methods.

I think the simplest way to say it is that, although static code analysis tools are useful (even necessary), the difficult, interesting bugs will always be found by humans. Code review just makes that happen faster.

Thanks for the nice post!