Why Develop Web Apps in the MEAN Stack?- 20 mins
A glance at the job market
Software development is a rapidly growing industry; the Bureau of Labor Statistics reported 1,114,000 software engineering jobs in 2014 and ten percent growth in job outlook from 2014 to 2024, compared to mechanical engineering with 277,500 jobs and five percent growth, and electrical engineering at 315,900 jobs and zero percent growth.
Figure 1: “Where the STEM Jobs Will Be”, BLS.gov data analyzed by the Computing Research Association predicts that 65% of the newly created STEM job openings in 2012-2022 will be in computing, followed by 17% in engineering.
The Computing Research Association analyzed the BLS data and prepared the chart seen in Figure 1. Computing is growing at a staggering rate compared to other jobs in STEM fields. However, software engineers continue to struggle with the early decision of which programming languages and technologies to learn on their entry into computer science. There are over three hundred programming languages, each with their own advantages and applications; to become fit for a job utilizing that language, one must dedicate a substantial amount of time committed to learning its syntax and usage then go on to build projects in the language to understand it at a higher level.
Who is this post geared towards?
Ideally if you’re reading this, you’re familiar with programming at least to a basic extent. You have an interest in web technologies and applications, along with their development and implementation; you may have taken a programming course in college or have reviewed a few tutorials to get your feet wet. However, if you’re very new to the programming world some of the terminology may confuse you. I try to explain some of the basics of web applications and the web in general, but some topics may be missed by people who haven’t worked with web development in the past. If you’re a seasoned veteran in coding/programming/development, the topics should come easy to you and you may benefit from the comparisons of the MEAN stack to other programming languages and frameworks.
What does this have to do with the MEAN stack?
How exactly do technology stacks work in an application?
A software stack commonly has the following:
Databases- databases manage your data and put it into a format so it can easily be modified. Database driven applications commonly use forms to move data to and from databases using the four basic SQL (Structured Query Language) commands: create, read, update, delete. Although MongoDB is a NoSQL database (which will be addressed later), it supports these commands.
Server-side framework – server-side frameworks generate the “back end” of the application. This allows you as a developer to add pages easily, create links between pages, add functionality with scripts, etc.
Front-End Framework – front-end frameworks allow the developer to customize the client side of the application and present information to the user. The client side is fundamentally what renders in the user’s browser when the site is visited. Front-end frameworks usually give the developer a clever way to manipulate data easily and in a unique, appealing way to the consumer.
For a quick summary of how a web application works:
User enters domain name into browser, this forms a request
When domain is entered (or link clicked), a request is made for the webpage document using HTTP, or Hypertext Transfer Protocol.
The web server where the webpage is hosted then provides the file to the browser, this is the response. The browser must also retrieve all the resources that make up the webpage: scripts, stylesheets, media.
Once all resources are retrieved and the Document Object Map, CSS Object Map, and the render tree are constructed, the browser connects them together and renders a page.
The user can then interact with the forms and content on the page, which will send GET/POST requests to the server and prompt it to manipulate data in the database and display the new values. Figure 2 from Upwork.com demonstrates visually how this process works. They break it down into five different steps, each very similar to what I explained above.
Figure 2: Basic breakdown of how a webpage works.
Carey Woodhouse from Upwork writes,
“Overall, they’re creating a web-based application that comes as close to a desktop experience as possible. Their focus is on user experience, and the technology they implement will hinge on how well it accomplishes that speed, efficiency, and smooth functionality.” (Woodhouse)
The reliance on speed, efficiency, and functionality forces developers to be very careful in their choice of programming languages and technologies. They want something that accomplishes these goals and is also scalable, easy to update, aesthetically pleasing, and robust.
Diving into Node.js
In an experiment performed by Kai Lei, Yining Ma, and Zhi Tan at Peking University, Node.js doubled the performance of PHP (one of the oldest, most highly used programming languages for the web) in a simple “mean requests per second” test, and scored seven times higher than Python-Web. Figure 4, shown below, outlines the mean time per request data of each prevalent web technology. Node.js has the quickest response time (although PHP comes close). In their study, they test many different benchmarks and Node.js continually comes out on top. For example, the group concluded in the 2014 study that Node.js was able to manage a significantly larger number of users than the other two technologies (Lei, Ma, Tan).
Figure 4: Results from “Calculate Fibonacci(10/20/30)” mean requests per second (higher is better), pulled from the Lei, Ma, Tan study.
An aside about MongoDB and RESTful web services
“RESTful web services are built to work best on the web. Representational State Transfer (REST) is an architectural style that specifies contraints, such as the uniform interface, that if applied to a web service induce desirable properties, such as performance, scalability, and modifiability, that enables services to work best on the Web.” The oracle documentation on the Java EE 6 Tutorial also explains the key principles of a RESTful application to be simple lightweight, and fast:
Resource identification through URI: A RESTful web service exposes a set of resources that identify the targets of the interaction with its clients. Resources are identified by URIs, which provide a global addressing space for resource and service discovery. See The @Path Annotation and URI Path Templates for more information.
Uniform interface: Resources are manipulated using a fixed set of four create, read, update, delete operations: PUT, GET, POST, and DELETE. PUT creates a new resource, which can be then deleted by using DELETE. GET retrieves the current state of a resource in some representation. POST transfers a new state onto a resource. See Responding to HTTP Methods and Requests for more information.
Self-descriptive messages: Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others. Metadata about the resource is available and used, for example, to control caching, detect transmission errors, negotiate the appropriate representation format, and perform authentication or access control. See Responding to HTTP Methods and Requests and Using Entity Providers to Map HTTP Response and Request Entity Bodies for more information.
Stateful interactions through hyperlinks: Every interaction with a resource is stateless; that is, request messages are self-contained. Stateful interactions are based on the concept of explicit state transfer. Several techniques exist to exchange state, such as URI rewriting, cookies, and hidden form fields. State can be embedded in response messages to point to valid future states of the interaction. See Using Entity Providers to Map HTTP Response and Request Entity Bodies and “Building URIs” in the JAX-RS Overview document for more information. (Oracle)
MongoDB supports all the above principles, making it a favorable candidate in the development of web applications. For example, in Figure 5 I’ve shown the return format of MongoDB data (JSON). This format allows for easy queries, the map structure is commonly used and very easy to understand.
Figure 5: Sample Data from MongoDB organized in JSON format
In the past, MongoDB has been criticized with regards to dropping data; some developers were very worried that it may not suit an application where transactional guarantees are needed. When dealing with currency or other very pertinent information, they said MongoDB was risky as there had been “cases” of MongoDB reporting a successful transaction when it didn’t go through. Eliot Horowitz, CTO and co-founder of MongoDB refuted these points. He points out that there have been some incidents but as the product is always evolving these bugs have been worked out and MongoDB remains a stable platform (HackerNews, Observer). I’ve included the detailed explanations of these issues in the references if these are topics of interest for you as a reader.
Growth/decline analysis of competing technologies
Quincy Larson, an instructor at FreeCodeCamp.com wrote a great analysis on the growth trends of web technologies from 2012 to 2016. In his analysis he says that large development teams are choosing to go with Node.js due to the “high performance and massive ecosystem of tools” (Larson). A few examples he notes of large companies making the shift to Node.js:
Walmart switched over to Node.js on a Black Friday, got more than 200 million visitors that day, and never went above 1% CPU.
LinkedIn rewrote their mobile backend in Node.js, and proceeded to get 20 times the performance out of 1/10 the servers.
Groupon increased page load speed by 50% by switching from Ruby on Rails to Node.js. They also reported being able to launch new features much faster than before.
Paypal did an experiment where two teams built identical apps - one in Java and one in Node.js. The Node.js team built theirs in half the time. The Node.js app had response times that were 50% faster than the Java app.” (Larson)
Node continues to allow companies to reduce costs and improve the performance of their web applications while scaling up and still minimizing load on their servers.
Figure 6 shows the percentage of job postings that mention Ruby on Rails versus Node.js, Python Django, and PHP Laravel:
Figure 6: Job Growth trend in relevant web technologies
According to the above figure, Node.js development jobs are on rise with almost double the amount of openings Ruby on Rails offers and ten times the amount of job openings available with PHP Laravel. Larson notes,
“Even with Node.js becoming dominant, some development teams will choose to build new projects using Ruby on Rails thanks to its documentation, developer-friendliness, and stability.” (Larson)
Thanks to the new Zend Engine 3.0, your apps see up to 2x faster performance and 50% better memory consumption than PHP 5.6, allowing you to serve more concurrent users without adding any hardware. Designed and refactored for today’s workloads, PHP 7 is the ultimate choice for web developers today. (Zend.com)
A two-time performance increase and 50% better memory consumption will not allow PHP to beat the performance of Node-based apps, as shown in the benchmarks of the Lei, Ma, Tan study. If PHP wishes to remain relevant there must be humongous improvements in runtime. Ruby on Rails has begun to fall behind as the trend for “isomorphic apps” develops. Isomorphic apps are applications “that can run both client-side and server-side. The backend and frontend share the same code.” (Isomorphic.net)
In Conclusion: The Lean, MEAN, App Developing Machine
Lei, Kai, Yining Ma, and Zhi Tan. “Performance Comparison and Evaluation of Web Development Technologies in PHP, Python, and Node.js.” 2014 IEEE 17th International Conference on Computational Science and Engineering (2014): n. pag. Web.
“From CTO of 10gen First, I Tried to Find Any Client of Ours with a Track Record… | Hacker News.” From CTO of 10gen First, I Tried to Find Any Client of Ours with a Track Record… | Hacker News. N.p., n.d. Web. 05 Dec. 2016.
“Is Ruby on Rails Fading?” Is Ruby on Rails Fading? – Larson, Quincy - Quora. N.p., n.d. Web. 05 Dec. 2016.
“PHP 7 Makes Powering the Web a Whole Lot Better.” PHP 7 Makes Powering the Web a Whole Lot Better. N.p., n.d. Web. 05 Dec. 2016.
Popper,Ben. “The Trolls Come Out For 10Gen.” Observer. N.p., 2011. Web. 05 Dec. 2016.
“Software Engineers” U.S. Bureau of Labor Statistics. U.S. Bureau of Labor Statistics, n.d. Web. 05 Dec. 2016.
“Mechanical Engineers U.S. Bureau of Labor Statistics. U.S. Bureau of Labor Statistics, n.d. Web. 05 Dec. 2016.
“Electrical and Electronics Engineers U.S. Bureau of Labor Statistics. U.S. Bureau of Labor Statistics, n.d. Web. 05 Dec. 2016.
Wodehouse, Carey. “What Does a Front-End Developer Do? - Hiring Headquarters.” Hiring | Upwork. N.p., 2016. Web. 05 Dec. 2016