Compartilhar via


Azure Mobile Services save the day (or app)!

When Windows Store first opened to all developers, I created an app Movieoholic which pulls in data from Rotten Tomatoes (RT), YouTube, and Wikipedia to provide all the information that one wants to know about a movie. Frankly, I didn’t have very high hopes from the app so scalability was the last thing on my mind. I just created the app and got it into the store.

Now the thing about RT API is that it is rate limited – 10000 calls per day, 10 calls per second. This initially seemed fairly high number to me. So the initial version of my app didn’t implement any kind of caching mechanism. My app pretty soon got somewhat popular. After getting some good reviews, I started getting bad reviews about the app not working\crashing. I looked at the RT Developer dashboard and noticed that I was frequently going over my quota limit. To quickly workaround this I started caching the RT API responses on user’s machine; refreshing data from the API only when a time period of 24 hours has been crossed. In hindsight, I should have done this in the initial version of app itself.

Caching stabilized things for a while. But as the app popularity grew, I was again back to hitting my quota limits. I needed some kind of middle tier service which cushions the number of requests to RT API and most importantly, I needed to do it quickly. Enter Azure Mobile Services (AMS)!

I had known and played with Azure Mobile Services for quite a while then. But what pushed me into selecting it was when I had a chance to attend a session on it by Josh Twist (@joshtwist). I was amazed at the simplicity and power it provided and the rapid improvements and features that were added to it. I knew it was in good hands.

I am not going to list down all the cool features that AMS provides – Push Notifications for Windows, iOS, and Android, OAuth Authentication for Facebook, Twitter, Google, and Windows are just a few. AMS also provides a way to do some operation whenever an attempt is made to insert, update, delete or read a record from a table. These operations are written in JavaScript and because AMS fully supports Node.js you can easily make HTTP requests (require ('request') ; ) and take full advantage of its power. All this code is written in the browser window itself so we don’t need any editor for writing code.

Writing code in Azure Mobile Service browser window

In my situation to reduce the number of calls to RT API, my app now calls AMS instead. AMS in turn checks whether it already has the requested data in tables else makes a call to RT API and stores the data back in table for future requests and also return the data back to the client – all this code written in JavaScript! This mechanism coupled with the caching at user’s machine level means that I remain well with in my quota limits. Problem solved.

To make things even simpler, AMS provides an SDK for Windows Store apps (apart from SDKs for other platforms). They also provide a sample app showing how to use the SDK. In fact the whole operation to migrate my app to use AMS was so easy and smooth that I was able to finish the process in a day, testing included!

If you are developing a mobile app for any platform, I highly recommend considering Azure Mobile Services for any kind of network communication. You won’t be disappointed.

Comments