SQL vs NoSQL, Which is better?

Manikant Jha
2 min readMar 13, 2022

Here is an example SQL Database👇

Here is NoSQL Document

Example NoSQL Database

Nowadays we have a general perception that NoSQL is better than SQL, We should always use NoSQL(ex: MongoDB, DynamoDB) to make our application more scalable, but that’s not true, here I am explaining use cases of both databases and when to use what.

Read and Write

If your application is gonna have features that perform lots of reads and writes in the table then NoSQL is better as all documents are kept in one single document so it is easy to retrieve all at once also while insertion you will be getting all data and once so read and write is expensive in SQL.

NoSQL is built for Scalablity

If you think in the future you might have another column (from the above example:- if I want to add column phone no. in the table it is an expensive operation in SQL, whereas in NoSQL it is quite cheap like we can add a new key phone no. and then all new users will have phone no. from now in Database.

Sharding is inbuilt

we use Database sharding to distribute data across machines to reduce load. NoSQL(ex:- MongoDB) provides this inbuilt, whereas it is huge pain in SQL databases.

Built for analytics and aggregations

NoSQL DBs supports data matrix quite well, like if you need total likes or avg. salary or total users NoSQL performs better.

Those were advantages of NoSQL let's come to disadvantages.

Update and Delete

Operations like redaction and deletion are expensive in NoSQL as data may not be consistent as two nodes may have different data for the same id. While SQL gives us ACID property (where C is for consistency).

Transactions

From the above point, as ACID is not provided by NoSQL, we cannot have transactions using that, that’s why fintech doesn’t use NoSQL.

Reading one property of the entire table

NoSQL databases are not optimized to read one column of the entire table, it is also not great in SQL but as of now, it is better than NoSQL.

Relations

R in RDMS is for relations which helps to join tables and read data efficiently. As there are no relations in NoSQL, joining tables becomes hard, it is almost manual in NoSQL, you have read all data and merge them together.

Whereas SQL is built for this, inner join, outer join you know.

So, if you are going to make a few updates and no transactions, NoSQL is better.

--

--

Manikant Jha

Solves Problem with Code, Sometimes i design too.