Architecture for Web and Mobile Clients

Architecturemobilemvc

The application that I work on needs to have a web interface (ASP.NET MVC) and mobile interfaces (Android/IPhone native). The features for mobile applications and web application might not overlap (some features are similar, some are different)

At the moment, I'm thinking of 2 ways to structure the applications like below:

enter image description here

For the top approach, just need one web server that server both web and mobile clients. Mobile will communicate with server through Json (serialized by ASP.NET MVC). The service layer is just a plain class library to be referenced by web layer

  • Pros
    • Faster, since there's no cross-machine communication between web and
      service layer
    • Simpler
  • Cons
    • Security? Any security concern here?
    • Less flexible when scaling (can only scale both web and service layer as one unit).

For the bottom approach, need one web server and one application server (for WCF/Web API). Mobile will communicate directly with application server through Json

  • Pros
    • Can secure web and application servers separately, extra layer of protection on application layer. But the application server is exposed to mobile anyway right?
    • Can scale web and application servers independently
  • Cons
    • Slower
    • More complicated due to WCF/Web API in the middle

It's the first time I do the application for both web and mobile like this. Which approach is commonly used in this scenario? User tends to favor bottom approach, but I think in this case it might be overkill to follow bottom approach

Best Answer

The main problem that I see is that with the top approach, your website needs to be able to accept requests from mobile, as opposed to the services. That seems like something the website should not have to worry about. In particular, it implies either your website has a bunch of "pass-through" logic to duplicate the API of the services, or the website is providing a different API from that of the services (probably a little of both). Either way, that's a huge maintainability problem. Plus, it adds one extra hurdle (and potential bottleneck) for mobile requests to jump through, compared to talking to the services directly.

The claims about needing one or two servers in each case are really an orthogonal issue: You can put the website and its services on the same server if you want (I've done this many times at my job). Whether you do that or not doesn't have much to do with whether or not the mobile client is talking to your web page or your services. I would expect this decision has more to do with (as you pointed out) security or complexity, or perhaps with scalability (ie whether the bottlenecks are in your services or your website). But for a sufficiently large/complex/important website, I believe these factors would all lean towards using separate machines.

Therefore, I would recommend the bottom approach.