Rohit Satwadhar
3 min readSep 16, 2023

SQL VS NoSQL: Battle of requirements

Photo by Sunder Muthukumaran on Unsplash

Okay, Let’s get it out. Choosing a certain DB because you happen to know it is a really bad justification for your choice.

People must have told you to choose DB based on your requirements. But if you are a tiny bit like me this makes very little sense. Unless you know which factors to look for, you can not make a checklist of these requirements. So when I was faced with this problem. I read, and referenced multiple resources and finally was able to make sense of which factors I should consider. Here I will share those factors so you can also make informed decisions.

Structure of data (Schema)

SQL DB structure is very rigid in nature. So if your data follows a particular format, which won’t change much. SQL DB is a good choice.

But if you are working with the ever-changing data model. NoSQL makes a good choice. NoSQL offers vast flexibility. You won’t have to deal with many issues arising when you try to add a new column to an existing database which has a lot of rows.

Scalability

Scalability is important when your application gets a lot of data. Your DB must be able to handle, store and retrieve data in an acceptable manner.

There are two types of scalabilities: Vertical and horizontal.

Vertical means you add more RAM and CPU power to your DB server. Horizontal Scaling means you add one more server to your fleet. So in horizontal scaling your DB will be spread across multiple servers.

SQL DB provides vertical scalability. Though you can use partitioning logic or sharding to scale horizontally, it is not well supported.

NoSQL DB has built-in support for horizontal scaling. NoSQL makes a good choice if you have a very large amount of data to be handled. Horizontal scaling is much easier and cheaper than vertical scaling.

But remember you can also use sharding with SQL for horizontal scaling. So if other factors like Data integrity are important, you might consider SQL DB too.

Data integrity

SQL has a huge advantage here. If you want your data to be consistent in near real-time. SQL is your best bet. SQL databases adhere to ACID principles (Atomicity, Consistency, Isolation, Durability). So if one user makes some change that change will be propagated to every other user in near real time. Situations like financial transactions where data integrity is paramount. SQL makes a default choice.

NoSQL adheres to BASE principles (Basic Availability, Soft state, Eventual consistency). This means that if a certain user makes some change, other users might not get the same data in real-time. In a distributed environment it might take some time for data to be consistent.

So if data consistency is your top priority, SQL is the solution for you.

Querying

SQL is a quite mature DB. It supports complex querying including JOIN queries. This helps users to use inter-table relations to the max.

NoSQL does not support such complex querying. NoSQL databases use different languages based on DB. For example, MongoDB uses a JSON-like query language, while Cassandra uses CQL (Cassandra Query Language). These languages may be less expressive than SQL for certain operations.

Conclusion

In conclusion
if you want high availability , high read performance, easy scalability and flexible schema: Use NoSQL

If you want data integrity, ACID properties, and complex querying capabilities use SQL.

Rohit Satwadhar

I Write about new things that I learn. That is how I remember stuff. These things are mostly tech related.