When to choose No-SQL vs SQL?

Deepak Maheshwari
4 min readMar 13, 2023

--

These days, with the rise of internet and cloud technologies — and the proliferation of data that went them — made “Data” as one of the key aspects of any organization’s success. Data can bring a lot of value to any organization. As the world is moving towards data-driven decisions and new data is being generated at skyrocketing speed which directly poses challenges in terms of storage. Also, these days, data storage is not all about storing records but also includes storing unstructured data, payload, etc. AI/ML and Analytics are bringing a great deal of automation and insights for business, so it is also important to where and how we are storing data.

Additionally, for anyone trying to store brand new data or migrate existing on-prem data to the cloud there is always a question — should I choose SQL or No-SQL database? This article will help in bringing clarification to make the right decision between SQL vs No-SQL databases.

If we look at history then SQL databases have been a proven option since the 1970s. They are made up of highly structured tables, consisting of rows and columns, related to one other through common attributes. Every column is required to have a value for its corresponding row.

NoSQL (“not only SQL” or “non-SQL”) databases came along later to break the relational table with the ability to store and access all data types, structured and unstructured, together. They’re extremely flexible and easy for developers to work with and modify.

SQL vs No-SQL

What are the different parameters should anyone consider when deciding between SQL vs No-SQL?

At a high level, SQL databases use SQL (Structured Query Language). NoSQL databases use JSON (JavaScript Object Notation), XML, YAML, or binary schema, facilitating unstructured data. SQL has a fixed-defined schema, while NoSQL databases are more flexible. Let’s understand specifics of when to use which one —

When to use SQL Database?

  1. Suitable for strong structured data — SQL Databases are used for normalized structured (tabular) data strictly adhering to a relational schema
  2. Optimized for ACID transactions for OLTP transactions.

Defination for ACID (A- Atomicity, C- Consitency, I- Isolation and D- Duration)

Atomicity: Any transaction that updates multiple rows is treated as a single unit. A successful transaction performs all updates. A failed transaction performs none of the updates, i.e., the database is left unchanged.

Consistency: Every transaction brings the database from one valid state to another. It guarantees to maintain all database invariants and constraints.

Isolation: Concurrent execution of multiple transactions leaves the database in the same state as if the transactions were executed sequentially.

Durability: Committed transactions are permanent, and survive even a system crash.

3. Scales vertically — If the data volume is increased then hardware upgrade is required for additional storage capacity and a high performance

4. Support strong consistency ( all or none) and high data integrity

5. High availability is basic

6. Efficient complex queries and joins are required to pull data across tables against structured data, including ad hoc requests.

7. Looking for strong community support as SQL is a popular standard language that is well supported by many different database systems

8. Smaller volume and limited growth of data. Not suited for large data volumes like big data.

When to use No-SQL Database?

  1. When the schema is not fixed and requirements keep on changing then it is a good idea to start with No-SQL.
  2. Mainly used for non-relational data, e.g. key-value, document tree, graph
  3. More reads than create, update and delete
  4. Scales horizontally, scaling is done by adding more machines.
  5. Eventual consistency is required
  6. High availability and throughput
  7. Data is stored as strongly-typed columns rather than rows, making it possible to query and aggregate large volumes of data very quickly
  8. To streamline development and avoid the overhead of a more structured approach. Ease-of-use for developers that fits well with modern, Agile teams.
  9. Low-cost infrastructure

Use case examples:

  1. If you are starting a new project in the Agile approach where all the requirements are in the evolution phase and there is no strong relationship between data models then No-SQL can be a good idea. On the other hand, if you have clear business requirements with a defined data model then SQL is the best choice here.
  2. If you are working on analytical use cases then SQL is preferred
  3. If you are dealing with unstructured or semi-structured data like documents, JSON, and XML structure then No-SQL is the obvious choice
  4. No-SQL is preferred if you are dealing with in-memory data, it serves as a fast cache.
  5. Geospatial data is a good use case for a No-SQL database.
  6. No-SQL database is used for Internet of things (IoT) and sensor data use cases
  7. NoSQL database is a great match for e-commerce companies with massive, growing online catalogs and loads of inventory to manage.
  8. For Banking and financial transaction scenarios between multiple tables, SQL is preferred.
  9. No-SQL can be used for 24/7 use cases due to fast response times with extremely low latency, even as a customer base expand

Conclusion: Selecting the right data store is crucial, if the decision is made right then it can simplify the application scaling and availability otherwise a wrong choice can be friction and may result in performance concerns too. We should consider the data type and workload requirements to make a selection and at the same time, we are not limited to one database type over the other. Many organizations have implemented both SQL and No-SQL databases to meet their different requirements, making it possible to get the best of both worlds. I hope this article will help you to make the right decision between SQL and No-SQL, good luck with whichever you select based on the use case.

--

--

Deepak Maheshwari

Technical Enthusiastic | Sr. Architect | Cloud Business Leader | Trusted Advisor | Blogger - Believes in helping business with technology to bring the values..