Friday, November 1, 2013

Single Page Application vs. MVC application

Currently I am facing the decision to choose the front end between the popular and kind-of-mature AngularJS based single page application (SPA) vs. the less-exciting ASP.NET MVC application.  I came across this article The "SPA Tax", it lists the following reasons showing that SPA is more expensive than MVC:

Some reasons why it is more expensive to build a SPA vs. a normal MVC application as of 2013:
  • You need more experienced web developers that understand JavaScript better than the usual Web Developer (higher labor cost)
  • There are more pieces to assembling a SPA (example: multiple javascript libraries from multiple authors are needed) than a MVC application (R&D cost and maintenance cost)
  • Development tools are not yet on par with normal MVC application development (time added, so more labor cost)
Though it has some cents in terms of development tools. The need for more experienced developer and more pieces to assembling is trivial. What hold me back to not using AngularJS as the front-end now is the impedance between JavaScript and C#.

The reason I like C# and .NET so much is that it addresses a big (the biggest technical ?) headache in application development: the ORM. As long as a relational DBMS is used to store application data, then LINQ and Entity Framework combined brings the most development productivity you can find in today's development environment. So I choose C#/.NET as my back-end development programming tool.

Then when you compare any SPA with ASP.NET MVC, the pros and cons become obvious: using any SPA (AngularJS, Knockout etc), you need to define all view models again in JavaScript. Coming with this re-definition of view models, you also need to replicate all validation rules in the client side. For large application, it could be a big burden.

When should I choose SPA as my front end? It is the day that I can use the same programming language (TypeScript, JavaScript or Dart) to seamlessly access the back-end data repository. When JavaScript-based database such as MongoDB is mature enough to support real-life business transactions, we can use JavaScript in both front end and back end. Then there is no reason to not use SPA in the front end.

So the timing depends on the back end database layer. The key is to make ORM really easy with JavaScript. W can use JSON-based database for all business transactions. Both CouchDB (http://en.wikipedia.org/wiki/CouchDB)  and PostgresSQL(http://en.wikipedia.org/wiki/PostgresSQL)  have a great potential here.


2 comments:

  1. I've heard that BreezeJS is good for generating javascript ViewModels from entity framework metadata. Its like RIA services for javascript.

    ReplyDelete
  2. I Googled "mvc vs spa" and this article was the first entry. Congrads on that. I also enjoyed reading many of your other articles.

    ReplyDelete