One of the benefits of node is that it is light weight and highly scalable. It differs from other synchronous frameworks out there like ruby on rails, and ASP.NET. Node js is also one of the best choices when it comes to buildimg a suitable backend API for your project. Read more about API’s here. Let’s use a scenario to explain all these concepts of Node for easier understanding.
Let’s use a restaurant in this case, where we have a waiter taking orders from a table. Once the order is taken, the waiter takes the order to the kitchen, which handles the request of the customer at let’s say table 1. Now while the kitchen handles that request, the waiter is free to move to other tables to take in more requests for the kitchen to handle, this simply explains the asynchronous (non blocking) nature.
From this mini example, we can see that node handles request quite differently from other frameworks. Once a http request is gotten from the client (your browser in this case), the server accepts this request and while the request is still processing, which can take sometime because most of this request involves some database query, it would still be open to take in more http requests from other clients making your app more scalable in the process.
The Synchronous nature of handling http requests
The Synchronous (blocking) nature, which is in contrast with the ascynchronous nature handles http requests quite differently. Let’s use this same restaurant scenario but this time the synchronous version.
Here, the waiter receives the order from table 1, while delivering the order to the kitchen, he remains there till the order has been processed before delivering the order to the table. Now while the waiter waits in the kitchen, he does nothing helpful there which makes him useless till the order is complete, before he can finally take orders from other tables. By then, customers on those tables would have to wait a long time before they get to see a waiter to attend to them which is a bad service.
Well, it won’t be that bad if the restaurant employs multiple waiters to handle different orders. Now let’s get back to the technical explanation of this shall we?
Once the server receives the http request, no other http requests would be accepted by the server till it’s done handling the current request. This wouldn’t be noticeable because servers are usually powerful machines which handles millions of requests in a second, it wouldn’t be appropriate once your number of users (clients) begins to grow rapidly, rather you would need to purchase extra hardware to handle more requests. It doesn’t offer as much scalability as the ascync nature.
When to use Synchronous and the Ascynchronous frameworks
Even if they both have their advantages and disadvantages, there are benefits when it comes to the kind of application you want to build.
If your application is built to be accommodating alot of users with millions of requests sent per second, then node is the right choice for you. But if you’re building something that requires large file processing like image manipulation or video encoding, rather the synchronous frameworks like ruby on rails would be preferable.
Hope you enjoyed the article, your can follow us on social media to stay updated when ever we upload a new article.
Your favourite software developers. Kudos!