After doing a lot of research and watching several videos about Node.js technology, I was able to learn a little more about what it is, how it works and why it stands out among other technologies.
What is Node.js technology anyway?
It may be that reading this, you still do not understand what Node.js is, but by performing my research, I found an enlightening example, which may allow you to understand this technology that is talked about so much.
We can compare Node.js to a restaurant. Follow me in my reasoning:
Customer 1 arrives at the restaurant and sits down at a table, promptly a waiter goes to meet him, notes his order, and takes him to the kitchen. While the order is being processed, new customers arrive at the restaurant, so the waiter meets them and repeats the same process as for customer 1. When customer 1’s order is finalised in the kitchen, the waiter takes it immediately to the corresponding table. And so, the process repeats until the end of his workday. Is this correct? This example, as simple as it sounds, clearly explains how this non-blocking single-threaded architecture, Node.js, works.
Taking this example to a more technical view, we replace the restaurant with a web application, which will have the function of returning simple information from a database. We can say that the users correspond to the customers, the employee to the single thread and the kitchen to the processes, like the example of accessing the database.
And the process happens just like in the example.
The fact that this architecture is non-blocking is a particularity that allows that when there is a request for an event, it does not stop being carried out because there are other events waiting to be finished, that is, using the example of the restaurant, if a certain customer makes an order that takes less time than other orders he will be immediately served as soon as it is finished in the kitchen not having to wait for the previous orders to be served. Thus, a non-blocking technology is defined, the actions do not get stuck or have idle time and neither does the application crash while waiting for the event requests to be completed. So even when a request is made, the user is free to perform any other interaction with the application while waiting for the processing to respond, thus allowing the user to have a much lighter experience.
The other difference between Node.Js and other technologies is that it is single threaded as opposed to other languages that are multi-threaded.
What exactly does this mean?
Taking the restaurant example one last time, it means that in Node.Js the “restaurant” has only one employee and in other languages your “restaurants” have more than one employee running at the same time. So how does this work? In the Node.Js technology restaurant, the employees take the orders and send them to the kitchen as the customers come in, but delivers them to serve as they finish, as I said, without waiting for the slower orders that came in first to finish. In other technologies, when customers order from the various waitresses, they talk to each other to speed up the various orders that arrive. What is the big problem of this restaurant with so many waitresses? It has a very heavy structure which means that if there are many orders, with the employees talking to each other, it causes disorganization between the waitresses and entropy, which can delay the orders, while in a single thread restaurant there is no such limitation, but there is the fact of being a single employee and not being able to respond to many orders at the same time.
So, bringing it to reality, in multithreaded languages for each new request it is necessary to open a new thread, and if this thread limit is reached, it is necessary to wait for a thread to finish to be able to make room for a new one. So, to avoid an overcrowding of threads, it would be necessary to join more servers, getting more costs. And unlike multithreaded languages, Node.js seeks more performance with less cost!
Uber,Paypal, Netflix and Walmart.
Currently large companies already use the architecture of Node.Js, such as Uber, Paypal, Netflix and Walmart. To finish, I’ll present a statement from Paypal about the use of Node.js: “Paypal Developed the same application in Java and in Node.js and the latter was developed in half the time with fewer people, with 33% fewer lines of code and 40% fewer files, plus it increased the number of requests-per-second by double compared to the Java application and decrease the response time by 35%.”
This technology is practical to write, makes the user experience lighter and can be an excellent choice for developers looking to learn new technologies.