- Magento is full of boilerplate code which obscures the programmers intention
- Magento 2 has legacy ORM and framework based on outdated Zend 1 components.
- Magento 2 teaches a lesson: papering over complexity creates more complexity
- Magento was a “design by committee” project that covers everything of everything in the eCommerce application development, hence is exceedingly complex slow and buggy.
- The experience of Magento programming is it’s ok until it isn’t, until that day an obscure impossible-to-understand Exception appears out of the depths of a stack trace of Aspect-oriented plugin interceptors you've never heard of requiring 3+ days just to figure out the problem. Magento 2 has huge stack traces. They go on for several screens full of abstract method this and abstract method that.
- What is the overhead required in the framework to allow coders to write zero code?
- You need PHP Storm IDE with custom plugins to work with Magento codebase, they are a symptom of Magento complexity
- Node.js was the result of one guy honing and refining a vision of a lightweight event-driven architecture until Node.js revealed itself
- The solution for Callback Hell, the async/await function, is an example of removing boilerplate so the programmers intention shines
- Coding with Node.js is a joy
- The npm/yarn package management system is excellent and joyful to use, versus the abomination that is Composer
- Node.js performance is riding the coattails of Google investment in V8 to speed up the Chrome browser
PHP vs. Node.js
What is Node.js?
Some facts about Node.js
- Node.js was developed by Ryan Dahl in 2009
- Unlike PHP, Node.js doesn’t need a separate web server(Apache, Nginx).
- It uses npm package manager- the largest software registry in the world.
- Tech-giants including IBM, GoDaddy, PayPal, LinkedIn and Netflix are also adopting Node.js.
PHP has a sound code base while Node.js has more modern features
Popular platforms for building websites (including Drupal, Joomla, and WordPress) are written in PHP. PHP has a deep legacy codebase. However, for better performance, you can’t optimize the Magento 2 PHP Core code. It is too bloated and overengineered using bed software development practices based on deprecated Zend Framework 1 library.
On the other hand, Node.js has modern features and interfaces. With its features like Node streams, module caching, event-driven architecture, it is capable of handling multiple client requests simultaneously with ease. It has a modern syntax that helps developers to easily configure and extend the application. But as compared to PHP, Node.js developers must have a good understanding of callback functions and closures.
Look at the given chart. It displays the total number of concurrent requests per second.
From this chart, we can see that Node.js handles multiple concurrent requests in less time as compared to PHP. However it is the performance of the Raw PHP Magento has a really slow framework and can handle just sing request at a time.
An example to understand how coding strategy differs in PHP and Node.js
Suppose you want to add new sections into your website. In Magento, you just need to open PHP tags and start writing codes in the PHTML files(called mixing code with HTML content). Due to this, it becomes difficult to maintain and extend the code in PHP.
But Node.js doesn’t follow the ‘mixing code with HTML content’ approach. It implements a Model View Controller (MVC) architecture in which the view level (user interface layer) is separated from the logical structure (business logic). This, in turn, helps developers to write a more organized and maintainable code that can be easily extendible in the future.
2. PHP/Magento is synchronous while Node.js is asynchronous
Before delving into this point, let’s understand what synchronous and asynchronous program code means.
- Synchronous: In this, one line of the code is executed at a time. The next line of code is executed only when the previous line of code has been executed completely.
- Asynchronous: In this, the entire code is executed at once. It means two threads can run parallelly and are independent of each other. They don’t interrupt each other at the time of execution.
The given image shows how execution time is faster in the asynchronous program code than the synchronous program code.
Unlike Node.js, no client app is needed in PHP (they build everything on the server)
Application Scenarios for PHP and Node.js
- Simple Content Management Systems (WordPress or Drupal)
- Applications that use LAMP stack. If you don’t know what LAMP stack is, then here is some basic information for you:
What is a LAMP stack?
- It is a set of open-source application, used to create web-based applications.
- LAMP stands for- Linux operating system, the Apache HTTP Server, the MySQL relational database management system, and the PHP programming language.
Note- PHP is the best solution if your client prefers a shared hosting service instead of full-fledged virtual cloud instance. It is a portable web application solution that can run on almost any server (Apache, Nginx) and any operating systems. Thus, it makes the deployment and integration process easier.
- Building PWA, single-page applications, real-time chats, collaboration apps, MAgento microservices, IoT applications, streaming apps and more.
- Developing highly scalable server-side applications (with its non-blocking I/O and event-driven architecture).
Why NodeJS for Magento ??
>Because it is popular
Simple right? Lots are people (and companies) are interested in node js, it has the fastest-growing communities (better SO questions to copy and paste solutions) and largest library counts.
> Asynchronous IO
Why does it matter? Because Async IO improves the performance of a system considerably.
> Simplified Build processes
I love Magento, I am a fan of it. Magento has revolutionized eCommerce development. But there is just one issue. I have to write configurations in XML, I mean seriously, XML is was not designed to support programming logic.
With Node js, you can do it all, knowing just one language.
When database spits out data, developers go to an extent converting those tuples into meaningful objects, remember all those ORM mappings, GraphQLs. Well, don’t need to do anything with node, the result comes in JSON format.
Clearly, Json is the first-class citizen in node js. Not quite correct when I talk about other languages, of course, there are mappers, but then are they are just mappers.
> Fast and Scalable
Who doesn’t loves speed? People love to praise the speed of Node.js. The data comes in and the answers come out like lightning. Node.js doesn’t mess around with setting up separate threads with all of the locking headaches.
There’s no overhead to slow down anything. You write simple code without redundant Magento 2 complication and Node.js takes the right step as quickly as possible.