Home ...

Deciding a RDBMS or a NoSQL for NodeJS apps

Ragavendra B.N.
Ragavendra B.N.

In this article I will talk about the reasons for why to choose either a SQL or a NoSQL or even having an hybrid of both or your NodeJS applications. I will talk about the nedb for NoSQL and say mysql for the SQL.

  1. Installation -

Both nedb and mysql installation is similar like npm i nedb or npm i mysql2. In terms of mysql you might have to follow a few additional steps as documented in the other article.

  1. Disk size -

With nedb one part is evident is that data is stored, however there is a higher chance that you have more duplicates in it than the SQL one. The json object is more or less saved as is. With the SQL option the duplicates can be mitigated before loading the data into the table.

  1. Performance -

Data retrieval times for both the SQL and the NoSQL seem to be similar but SQL could fair better in terms of how data is organized and adding indexes to the relevant column or columns.

One aspect here is working more with the SQL is always helpful. There could be situations where data retrieval is really slow and all that was needed was to add an index to required column.

In terms of data load the NoSQL could take like for about eight plus hours for about 1879691 rows of three columns ( int(11), int(11), time) types and SQL like mysql could do it in about six minutes. One situation I faced was say I had a table about six hundred unique fields and since it was taking forever to load it, I tried to separate the unique files into independent tables or databases. However, there were other issues like file wrtes as well when this was done and a higher chance of data loss or discrepencies.

  1. Data retrieval -

Complex data retrieval is mainly possible through the RDBMS soltuion alone like the SQL JOINS or the INs . One might consider having additional columns instead of a JOIN could do for now, but it is all situational as well.

  1. Skills -

Having used the SQL for quite some time ago, it was one part to revisit it and learn it. Honestly identifying the data types like CHAR(10), INT(11), TIME(), DATETIME() and implementing it in the app was well worth the effort I must agree.

Summary -

No doubt that NoSQL is the word in every one's mouth lately, however it mainly depends on the need fo the application. Say if it is a simple log store is what is needed, nedb might be the way. Even for situations like mine where the data needed on the website is fetched from another system, nedb was failry doing well.