lunes, 2 de abril de 2012

Cloud Enhancement for your Smartphone

A couple of weeks ago I decided to develop an app intended to replace our grocery list at home -- we normally keep all items in a sheet of paper. The first alternative was to do the web app in HTML5 since everybody is talking about the power of the new javascript libraries, etc. so i couldn’t wait to implement it.

For the HTML5 version I developed a website (soon to be revealed to the general public) that allows users to keep grocery items under control. The website turned out to be more advanced than what I was expecting. It has plenty of business logic. There were items that if labeled weekly, would require a reschedule. There were other items that were “Reminder Only” to be scheduled some day in the future. And there were some other items that required a description in case there was a sale. Yes, my wife and I went crazy with the design. Therefore, I kept all the rules in the business layer and worked on the presentation layer leveraging on html5 to reduce the development time. (I used GAE for the cloud).

The first HTML5 release was a total failure. Although I did my testing, I did not realized how bad the 3G network coverage inside the commercial center is. Each time I marked an item as “checked out” it took forever for the connection to respond. I was always lagging a couple of aisles behind my wife trying to keep up with what had already been bought and what was pending. No wonder why I marked that we had bought soy milk when in fact we did not! (We just bought milk).

So it was time to go RESTful and do some more cloud enhancements. For the new redesign, most of the data is kept local vs 100% online. At the time the Android App is initiated, the app downloads the lists and the items for the specific user. It then saves them in the local database. The user then edits the items locally and syncs them at will. This design proved to be better than the HTML5 version. It was faster and more responsive.

Cloud Experience
It was pretty easy to set up the RESTful services in GAE. Although they do not provide a framework for those services, the open source community is pretty active on this area. I used Restlet, a framework with a pretty light library and pretty active user community, fresh documentation, and easy to use API. And because my friends always complain that I use Python, this time I used Java for GAE. The Restlet Framework has customized a release for Android apps, too. I also noticed that datanucleus, the persistence framework behind the Java GAE, also had RESTful interface but I did not use it.

There are some factors to consider while exposing your RESTful services using the cloud. You have to think about the warm-up period. Due to the nature of the cloud, most providers can put your instance to sleep if there is no activity. When the instance is brought back to life, your end user looses some precious seconds loading content. So I activated the warm-up functions in GAE and also updated some of the cron definitions for activating my persistence manager. After that the response time was down from 10 seconds to 600 ms. Huge improvements.

Other Frameworks
I was amazed at how many frameworks are there for Android and iOS cloud offerings. There are companies that give you an SDK and basically you can store all your data in their cloud for a fee. They take care of caching, serialization, security, geolocation, and performance. Funny because those are the same services that you already get from GAE or Azure. Some of the companies that I checked were Parse , Cocoafish , Urban Airship ,and Kii Cloud to name a few.
Conclusions
There is definitely an advantage in going cloud for Smartphone apps. One of the key factors for the clod storage is that most datastores are NoSQL. Therefore, your schemas can be modified without the pain of foreign keys or any restrictions which is great for the release cycle of Smartphone Apps that usually is every two weeks. So it is a very good solution.