Tech mahindra
Tech mahindra

Why MEAN Stack for your next WebApp

Posted by: Dhananjay Diwan On February 05, 2018 12:57 PM facebook linked in twitter

In today’s dynamic world, churning out rapid application prototypes with super-flexible design which adapts to volatile specifications is the key business requirement. This necessitates a software stack which gives the required freedom and power to the developer to assume a flexible, locally owned schema, in-built support for end to end testability and harness the ever growing open source repository of re-usable plugins for speedy iterations. MEAN stack has proven to be an attractive choice to fulfil the above requirements.

MEAN (MongoDB, Express, Angular & Node.js) is an open source JavaScript bundle for web-applications consisting of following components which can very well be used independently:

MongoDB - a schema-less (document-oriented) NoSQL database

Express.js - a server-side JavaScript framework running on top of Node.js

Angular - a browser-independent MVC JavaScript UI framework

Node.js - a server-side JavaScript runtime based upon Google's V8 JavaScript engine

Traditionally, the developer had to learn and master different programming languages for multiple layers.

Just for example, to develop a Java-based application it is necessary to have a good grasp of JavaScript for front-end validation, Java for server-side logic as well as good knowledge of XML and SQL.

With the MEAN stack, the story is completely different.

All you need to know and master is the JavaScript (ECMAScript) language for all the components from the presentation layer (Angular) to the database (MongoDB). \

With such an isomorphic programming style, not only there are significant productivity gains but better performance as well since the data transfer among the application layers takes place in the form of JSON (JavaScript Object Notation) format.

This greatly reduces the usual overhead and complexity associated with conversion between HTTP, JavaScript, Java, XML and SQL as the data flows between the layers in either directions.

Advantages of using MEAN Stack

Large pool of JavaScript developers: Java developers have always been at a premium for enterprise development. With the Web revolution, there was a large untapped pool of JavaScript developers out there to be leveraged for full-fledged Enterprise application development.

Young developers love the inherent freedom and flexibility of JavaScript (no compilation, no type declarations and no restrictive Object oriented programming principles to master before jumping in to write any code!) which meant a lower barrier to entry for new developers.

Declarative UX and testability: Over the last few years, Angular emerged as a clear winner among the plethora of confusing JavaScript UI libraries with its promise of code-less browser-independence, natural blending with HTML to adapt it for application development, two-way binding and finally, a clean separation of presentation from UI logic.

To tame the uber-flexible dynamic language and bring predictability to the output, open source BDD-style unit testing tools like Jasmine, task runners like Karma came handy.

Cloud-hosted continuous-integration services like CircleCI make life easier.

Easier debugging and code-reuse: When you have a single language to work with across layers, it becomes easier to trace the execution thread, watch how the data gets manipulated and debug the flow with a consistent set of free open-source tools.

Libraries developed once can be seamlessly reused for front-end as well as back-end resulting in significant boost to productivity. The thriving npm.js repository for every imaginable task in hand is the proof of the pudding.

Scalability: Node.js’s underlying V8 JavaScript engine by Google is known to utilize server resources efficiently due to its non-conventional single-threaded execution model, which is a notable departure from the classic Java (and C#.NET) multi-threaded way of handling concurrent execution, synchronization, locks etc.

Node.js provides testable concurrency without the headaches and uncertainty of multi-threading/cron jobs. First, the I/O based event loop architecture and C++ core modules deal with thousands of requests with ultra-frugal utilization of CPU and memory unlike a JVM.

In addition to that, the dynamic load can be handled by leveraging the Cloud’s natural horizontal elastic scaling capability by launching additional instances on the fly. Finally, MongoDB’s cloud-ready replication and sharding features boost the performance with great availability.

Variations of the MEAN Stack

Since the term MEAN was first coined by Valeri Karpov (a MongoDB engineer) in 2013, it has gained significant popularity in Enterprise world for serious business application development.

However, after the initial excitement established the concept that such a new combination can finally give a serious competition to the Java based well-established behemoths, it was natural that developers and organizations began customizing the stack make-your-pizza style as they preferred different components for various layers in the originally proposed MEAN stack such as,

1. MERN – Replacing Angular with React.js

While Angular.js was great framework of its kind, it had a steep learning curve, lacked good support for mobile web apps.

Google – the creators of Angular.js, fixed these issues to a great extent with an all-new 2.0 version named just Angular (latest stable is 4.0 at the time of this writing).

Facebook in the meantime released its JavaScript library called React.js which is not a full-fledged framework, allowed the flexibility to mix-and-match third party libraries like Backbone.js and promoted an event-driven “reactive” style of programming and a virtual server-side DOM (Document Object Model).

Since then, Angular has tried to keep up the race with improvement over the original design but the MERN stack has now grown as an interesting alternative.

2. MHAN – Replacing Express.js with Hapi.js

While Express.js is a good lightweight framework handling client-requests efficiently providing good performance rivalled only by raw-http processing, it still has some limitations, which can be a concern for Enterprise-grade projects.

For this reason, Walmart Labs developed another open-source alternative called Hapi.js which provides some features like better error handling, modularity, clean separation of configuration from request handling, great plugin system, built-in support for popular authentication/authorization schemes and greater abstraction from the http model.

Future of traditional stacks (Java, .NET, Python, Groovy and LAMP)

The MEAN stack (and its variations mentioned above) is set to give a tough fight to the traditional Java/.NET stacks when it comes to creating fresh apps with their own schemas.

The old stacks are here to stay for a long time due to years of investment and working functionality that nobody wants to rewrite in a flexible new language.

Also, extending the functionality in those projects is still a big task which is best handled in the same language. That’s why we see a sudden rise in popularity of Java-based micro-services stacks such as SpringBoot from Pivotal.

However, the same can’t be spoken about other competing stacks like Python (with Django, Flask etc). It may continue to exist but may not take over the game completely beyond their niche, simply because there is no competition to JavaScript in the browser, which gives the MEAN stack an unfair advantage over beautifully simple and powerful server-side languages like Python/Groovy and even Scala.

What happens to LAMP Stack

The hugely popular LAMP (Linux, Apache, MySql, PHP) stack which is often compared with MEAN isn’t likely to get the lime-light once again.

While Linux will continue to thrive, no doubt as an OS, developers are going away from MySql since the takeover by Oracle. There is a trend of migration to MariaDB (open-source community fork of MySQL) or PostgresSQL.

PHP never was a clean way to separate UI from logic and the long-time king of web-server – the Apache Httpd is getting serious competition from the likes of LiteSpeed and Nginx when it comes to ease of configuration and performance.

Overall, while LAMP web applications will continue to be maintained for quite some time, for new projects it seems it may not be the attractive choice any longer as highlighted in recent InfoWorld article with detailed reasoning.

Conclusion

MEAN is likely to stay here as a popular full-stack development option, especially for spinning out quick, loosely coupled web apps and ReST (Representational State Transfer) based API services.

However, it was built with the assumption of availability of abundant good quality JavaScript developers. Though it largely holds true for open-source community.

Adopting such as stack is still awkward for existing Enterprise application developers who are still in deep love with their Java/.NET world of pure OOPs paradigms. But Microsoft has come to rescue with a familiar “OOP simulating” TypeScript language (a typed superset of JavaScript that “trans-piles” to plain JavaScript), it still pays to be good at pure JavaScript (ES6) and get comfortable with its features. Organizations who invest in reskilling the old developers for acquiring strong JavaScript skills will surely reap the benefits in near future.

About Author

Dhananjay Diwan, Principal Consultant, Tech Mahindra @RapidFireDD

Dhananjay has received Masters in Computer Management from University of Pune in 1992. He has 25+ years of combined experience towards freelancing, academia and industry. Currently, he is leading Web/Mobile, Cloud (PaaS) and IoT initiatives from Technical Learning Services apart from facilitating and coaching the teams on Design Thinking.

Tags: Run Change Grow
 
(*) symbol is mandatory field
Name:
* Email Address:

Comments

(*) symbol is mandatory field

Post a Comment

* First Name:
* Email Address:
URL:
Comments:
 
Image Code
* Enter Image Code

Contact Us

Archives

For further information please write to connect@techmahindra.com

For further information please write to connect@techmahindra.com