Friday, July 17, 2009

MVC in the world of AJAX and SOA

Recently I was hit with the question - How does MVC play in AJAX world? Well, below is the perspective I put forward although not so eloquently or in such detail. My response expanded the scope from MVC and AJAX to include the more widely adopted back end architecture - SOA (Service Oriented Architecture). I am not sure if I was able to put across my thoughts vividly to the other person but based on the impression I got, I guess not. So I thought I blog about it to reach out to the online community and validate my thoughts.

Abstract:
The traditional MVC pattern requires a fundamental change in terms of the roles played by the three layers. This need arises from the advent of SOA at the server end and AJAX at the client end.
Please note that this is not about how the communication i.e sync or async occurs between the various layers. This is at a higher level and hence the sequence diagrams captured below may not depict the exact communication patterns.

Detail:
Traditional MVC has been:
Model: The data access layer and data persistence. This is the Hibernate, JPA layer in case of Java.
View: Presentation layer i.e how data is presented to user. JSP, JavaScript, HTML fall into this category.
Controller: Data validation, transformation and control the flow i.e identify the next view to be rendered. In case of Java, Servlets are used as controllers.





But in today's world where data driven architectures are replaced with service oriented architectures, the needs have changed with a diverse set of clients seeking the same set of information. The model is wrapped in a service layer that provides all the functionality required for diverse set of clients that include:
- A SOAP / WebService (i.e WS-*) client.
- API client i.e users need a programmatic access to the underlying functionality, either to enhance the functionality or integrate it into their own services.
- GUI - thin i.e web based, as well as thick i.e from IDE's such as Eclipse etc..

So in order to address the above needs, how can MVC help. Obviously the traditional MVC has to undergo few changes.
Model: is now wrapped by the service layer with enhanced set of functionality that enables distributed cache, scalability etc., across diverse set of client.

Controller: Since the data validation and transformation are needed by all the clients, these need to be moved into Service layer. So Controller is now left with flow logic only i.e to identify the view for the corresponding user event.

View: Any business logic at this layer needs to be moved into the service layer since the application MUST exhibit a consistent behavior across the diverse set of clients. How this data is rendered to the user is what primarily exists in the view and is the prerogative of the client.

Before we dive into how the layers can be refactored, let us how AJAX influences the layers. In the world of AJAX, the web UI is designed in a more modular fashion and there is a lesser need to render the complete page for every event. Only a certain content on the page could be refreshed with a different data set. The view remains the same. For eg: when browsing contacts page, the set of fields displayed for each user - First Name, LastName, Address etc., are the same. What changes when a different user is selected is the value of the First Name, Last Name and other fields. In other words the view stays the same while the data set is what changes. So the only role the controller plays is delegation from view to service / model. In other words, the role of Controller has diminished to that of a delegator.

The question arises to which layer does the Controller now really belong to? Should it be part of the View since its only role is to identify the view? Probably yes. The result is, if the view needs to change, either for a complete re-write to upgrade to latest technologies or for refactor purposes, changes at the View layer will in all probability effect the controller layer or what ever we may call it. But it is not necessary that the service layer undergo's any change.




The above is something we were able to achieve using GWT. I am not sure how the wide range of MVC frameworks out there enable the above. But, based on my past experiences, in an effort to enforce MVC pattern these API and interfaces could be rigid, although I would request the experts on these frameworks provide their inputs.

Wednesday, July 8, 2009

Operating System - What I expect as a user

With Google announcing, late yesterday evening, a new Operating System Google Chrome OS (http://googleblog.blogspot.com/2009/07/introducing-google-chrome-os.html), my first reaction was - What? Another OS that does the same myriad of things or does it take the OS to total different level, that I as a user have always wanted?

This new OS is in addition to the already available Android OS from Google that was announced as part of its strategy for smart phones, set-top boxes and other embedded devices. Google claims the need for this OS is to address the needs of primary web users who need the basic functionality of Speed, Simplicity and Security. I would not be surprised if Google takes this to the next level where in the OS meets the needs of the advanced users - the desktop users. I have longed for innovation in OS's which have changed little over the past two decades. Some of the features I have longed in OS are:
- Negligible boot up latency: As a user I care little on what the OS is doing and expect that I be able to operate on my system as soon as I switch it on without having to wait for it to boot up its internals.

- Apply changes immediately: In case of Windows as well as Mac, there are programs that require restart of the system which is annoying especially if I am in the midst of some work and happen to install the updates for these programs.

- Versioning: Ability to store the changes to a file as user modifies it. Although Vista does provide a versioning system, the hard drive can fill up pretty quickly. I do not know the internals on how Vista stores these versions but I am sure storing just the diffs between the prevoius file should not exhause the hard drive easily. Assuming Vista stores only the diffs, then there is a huge opportunity here to device new means by which the diffs can be stored between two instances of the same files.

- Disk Usage Visualizer: This can be an immense utility that provides a 2D or 3D view of the space occupied by each file or application on the hard drive. For eg: Mac has an utility provided by third party developers - GrandPerspective (http://grandperspectiv.sourceforge.net/#download) that provides a 2D view of the disk usage. This enables optimization of the disk space by identifying unwanted applications and files and quickly getting rid of them. Typical use case is when multiple Virtual machines are installed hosting different OS. This utility helps identify the space occupied by the VM instance and optimizing or cleaning up some of the space.

- Ability to define the life cycle of an application or file: The ability to say when a file should be trashed, or when an application must be un-installed etc.. As a user who researches bunch of software, I tend to forget to uninstall trial downloads. It would be nice if the OS provided a way to notify user stating "this software license has expired, do you want to uninstall?".

- A better File exploration experience: Some of the most simple use cases are not handled by today's OS. The ability to flatten out all directories to view all the files in the parent directory. At times, I have wanted to view all the src files in the "src" directory. Unfortunately, either I traverse through each dir or use an Unix console to view all the files.

- Ease of personalization of the OS: One feature I would love to have is the ability to right click and add my own custom operation. This is possible today and is used by wide variety of tool providers in integrating their tool into right click option. But this requires understanding of the OS architecture and its API's. If these API's were agnostic of a specific programming language or uniform across multiple OS it would be worth while spending the time researching on it. Else to research each OS is a huge waste of time. One use case for this has been to add the ability to right click and encrypt or decrypt a file or directory.

- Backup & Recovery: Supposedly, Sun's ZFS does a great job in recovering all the files and ensuring no data loss or corruption. I would love to have these features in main street OS offerings such as Windows or Mac. There is enough important work that I do on a daily basis that I would hate to loose due to system crash or hardware failure. Once they crash, retrieval of data is not easy nor is it cheap. I had to shell out ~$1200 to retrieve the data on my hard drive that crashed on me. Incidentally the price of the laptop itself was around ~$1200.

- Sorting of Directories in File explorer tree: I would love to have a file explorer that sorts the directories based on the most used directories. By default, Windows tree on the left side sorts the directories based on name. But, given the personalized way that I work with my file systems there are couple of directories that I access more often when compared to most others. Hence I would love to have my top priority directories displayed at the top in the tree. This will avoid having to scroll down at times to select this directory.

The above are a few that are on top of my mind and as and when I recollect other features I would like to see in OS, I will add to the above list.