When NodeJs is not a good choice for your Project.
Tags: node, systemdesign, backend, framework
Published: 2021-01-06 11:59:49

## INTRODUCTION

"NodeJs is better than Php", "I would rather use Flask in my sleep cause Python >>>(greater)", "No vex, but Golang is clear" etc. We have heard so many arguments go on and on about things like this and it almost seems like there will never be an end to it.
Then there are the neutral guys that go, "Use what you know to start", then God will help you through the remaining journey. And to be honest, it might just be good advice because sometimes, worrying might be a bottleneck or we never really worry about how the language choice affects us. We mostly think, once our users go up, we scale vertically(finally leave AWS free tier plan and start paying😥😥😥) or/and we scale horizontally(we deploy more instances) and that is the headache of the Cloud Architect. As a Backend developer, let me just CRUD, funny how this actually means nonsense, no wonder some PMS disrespect us and say "how are you spending a week doing crud?". 
This article will mainly be my thoughts on "why or why not Nodejs" though, hope you have a good read.

**P.S : Any word with an asterisk has a short definition at the end of the article. **

## NodeJs
Generally, the NodeJs community has been getting larger and everybody wants a piece of it, and mostly for good reasons, my friend just finished a thirty minute Youtube video on Javascript(not Nodejs) a week ago, and he subscribed to "Team Php Slander" this week.
Like I said though, they do love it for the right reasons. 
* It is fast.
* Quick to learn as we already learnt Javascript for Frontend.
* Amazing community(slightly toxic to the Php guys).
* We love to say I use MERN or MEAN stack.

Even with all the good choices, there are times when Nodejs should not be our go-to, even if we do use it, we start worrying about handling a lot of other things we won't with a different framework.😥😥
The computer is bound by two types of tasks mainly, they are simply
* I/O Bound
* CPU Bound

### I/O BOUND
You have most definitely heard about I/O in the programming business, maybe you have and can't remember but it simply means input/output, something Computer teachers touch at least once in Js2 or 8th grade, not that I was listening.
In simple terms, **Inputs** are data received by the computer while **Outputs** are data sent out of the computer.
Any task that involves receiving data by the computer or sending data is typically an I/O task. Examples include reading from a database, sending requests to a network etc.
These type of tasks typically take time and increases the latency* of what we are doing, taking time does not mean you wait two weeks, but big companies spend a lot of money to save their users as low as 40ms, so every ms counts.
NodeJs is a single-threaded* non-blocking framework designed to handle these I/O tasks like a boss, and it does amazingly well at this task because of its nature, it's Event-driven* and this allows it to handle a series of events without worrying about multi-threading or thread-locks*. 
Meaning multiple I/O tasks are a breeze to NodeJs, runs through them like a pro, therefore the speed we talked about up.
This is why all real-time activities favor Node Js as they should. Most of the time our mid-level tasks are I/O bound by the way, so Nodejs shines, why they are rushing Node Js developers these days.

*P.s : This is not a Javascript stan account, frameworks like Tornado in Python, tend to do well in tasks like this too, I have tried it and can say it's really efficient but would not be recommended for the Google type of idea your startup has cause of the smaller community behind it, if you face an error not on stack-overflow, it's you and the frameworks developer that knows.*

*P.s : Other languages are not a bad choice for I/O tasks, Nodejs just does better and also saves you the complexity of handling threads and the issues that come with it*

## CPU Bound
I am assuming we know what a CPU is, and to cut a story short, a CPU bound task is a memory-intensive task, anything that has to do with large computing will be dragging the energy of our CPU.
These type of tasks are generally bad news for your Nodejs project, reason is the same with why it shines so well in I/O bound tasks, it is single-threaded, it is designed to handle every request extremely fast blocking out other requests in this time frame, the moment your requests are CPU bound and start taking a little time for the computer to compute it's final result, single threaded have cause problem.
The PHP guy is probably nodding and laughing at the NodeJs guy thinking, this is where I shine😂😂😂. I will leave no comment on that as I love PHP myself and will tolerate no PHP slander but Golang will generally be a really good choice in this aspect, we will discuss why maybe in a different article.
Python has also proven to do well with CPU bound tasks like Machine learning in production.

*P.s : There are ways around this for Node Js developers like splitting into sub-processes and some developers even think it's a really good choice CPU Bound task, check out this [article](http://neilk.net/blog/2013/04/30/why-you-should-use-nodejs-for-CPU-bound-tasks/), but generally on surface level, it isn't.*

### CONCLUSION
Picking an appropriate Backend framework for your language makes your life easier in the long run. But do not spend too much time when the resources are limited, you can always improve later. But if you can make a choice, the type of tasks to run is something to think about.

### Layman explanation of some Terms
**Latency** : This is simply the time it takes to process a user's request. *We always want smaller latency*
**Scalability** : This means handling more requests without sacrificing latency
**Event-Driven** : It means reacting to events that occur, rather than running the code line by line. An event occurs, then an action gets dispatched, here's a good [read](https://medium.com/high-alpha/event-driven-architecture-a-primer-f636395d0295).
**Thread-Lock** : This is when a thread holds on to a task, so other threads cannot mess with it, here's a good [read](https://web.mit.edu/6.005/www/fa15/classes/23-locks/).