Sunday, July 15, 2012

Architecture for Multi-device Applications: Part 2 - Implementation

Part 1 of the series on "Architecture for Multi-Device Applications" focussed on the bare-bore design.

In Part 2, we look at high-level implementation structure - a slightly more detailed version of the design discussed in Part 1, before we start opening the individual boxes.

One of the key aspects that we discussed in Part 1 was the separation between the "Application Server" and "Web Server" layer and argued that most of the applications that we come across in real world, daily life, don't really separate them... or rather we find them difficult to separate because of the choices that we have or we are "taught" in our life.

The diagram below summarizes what I am talking about...

Oh! Damn... doesn't this diagram look horribly close to the earlier one? Where's the difference / value-add?

Ok.... I heard you. As I said, this is still a high-level diagram but let's look at now the options available within each box:
  1. Application Consumption: Desktop Browser, Mobile / Tablet (Browser or Wrapped Browser), Internet TV, Mobile/Tablet Native applications.
  2. User Interface Servers: Also known as the frontend servers and preferably generates cross-browser / cross-device HTML5 / CSS3 based user interface, unless it's a native application for desktops / mobiles.
  3. Biz-Logic Access Layer: Also known as the backend servers. They provide controlled access (read: authentication / authorization) to the data from the store (as is or processed). The access, preferably, is RESTful - this, however, is not mandatory. This layer, typically, is very thin - parses the incoming data, passes on to the biz-logic layer and serves back the response.
  4. Biz-Logic Layer: Typically, they are no different than the Biz-Logic Access Layer in physical deployment topology. However, in terms of implementation, it may be libraries that are consumed by the backend (access) servers.
  5. NoSQL Access: I could have just called the data-tier as persistence layer but I strongly choose NoSQL because that where you really are able to get the scale. If you are writing an otherwise application, replace this box with data-access layer.
  6. NoSQL Store: The actual store of the data.
  7. Client-side Data Cache: You may need that for long-activities or offline access or otherwise.
  8. External Modules (Frontend): If your application provides UI-integration with other servers (say, Facebook / Twitter / Pinterest Social Integration or otherwise).
  9. Server-side Data Cache: I don't think there is any need to talk about its usefulness. Having said that, you may not always use it.
  10. External Systems (Backend): For any API-based integration with 3rd party systems (say, Facebook / Twitter data access and processing that may require application secret key etc)
I hope the structure is now clear. In subsequent parts, we shall dissect open each box and explore:
  1. What is it all about in detail
  2. External forces or uncontrolled parameters (e.g.: Browser etc)
  3. The options available
  4. Comparative study of the options - to decide when to use what
Keep watching...

Saturday, July 14, 2012

Architecture for Multi-device Applications: Part 1 - Definition

One of the questions that keeps coming to me over and over again is - what is an ideal architecture for multi-device applications or rather applications that cater to multiple devices like desktop, mobiles, tablets, internet-TVs and what not?

This is quite interesting and exciting as more and more frameworks get developed. We started the multi-device world with native apps and soon realized that the model doesn't scale. There came HTML apps (or what people naively refer to as HTML5). I won't call them as really HTML5 (HTML5 only) apps... since you can live with HTML4 and CSS2 for most of the purposes unless you want features specific to HTML5 - most common being using audio/video since Flash is unavailable on iOS (iPhone, iPad etc).

Cross-mobile HTML apps gave birth to fantastic mobile UI frameworks like Sencha Touch, jQuery Mobile. And to access device-specific capabilities without having to maintain multiple codebases, we have amazing stuff like Phonegap and Titanium.

Great. Now that we have some great frameworks, how can we leverage them to design our application architecture?

A very common architecture that we come across, doesn't matter how old it is - yet it is valid, is:

Notice how carefully the Web Server is separated from the Application Server. But do we really get that? Most of the applications (read: enterprise) have the Web and Application stacks on the same server... and that's not a good idea.

Why? Well... we can't scale the web (frontend, browser facing) servers as they tend to be heavier. Additionally, it gets harder to do a lot more of the stuff:
  1. Redirecting based on the origin of request - device-based (e.g. m. for mobile, www. for standard), region-based (e.g. /hi-IN for India based, /en-US for elsewhere) etc
  2. Caching - suddenly you start mixing the global-data (non-user specific), user-specific, module-specific (if the frontend is properly modularized) etc
  3. Security - Ouch! All your data-calls are made from the "common server" and a compromise there can leave you at bigger risk than otherwise
  4. And a lot more...
Basic rule is to ensure that the "backend servers" are separate from "frontend servers".

So, the question now that gets in - how do I implement this in real world? And how do these new frontend (read: UI) frameworks help... let's explore that in Part 2 of the article.

References:
  1. Sencha Touch: http://www.sencha.com/products/touch/
  2. jQuery Mobile: http://jquerymobile.com/
  3. PhoneGap: http://phonegap.com/
  4. Titanium: http://www.appcelerator.com/platform
  5. The architecture of Web applications: http://www.ibm.com/developerworks/ibm/library/it-booch_web/