SQL VS NOSQL Database
There are always different opinions and choices what you want to choose for you database in your applications.
Developers started to choose NOSQL DB like Mongdb more than the usual SQL db like oracle and so on. Is this right?
I do not think so.
When you started to think about the choice of database between SQL and NOSQL DB, You should based on your use case to compare what are the pros/cons.
Here are some main difference between SQL and NOSQL DB as good reference for you.
1.Data Structure/Models
Firstly you need to know what kinds of Data Structure/Models you will need in your application.
If it is freeform data, like Json,key-value, graph, search, then you should prefer to use NOSQL Database
NOSQL Database is more used for dynamic schemas for unstructured data.
2. Transactions
If you have very complicated data model and also need to execute heavy duty/complex transactions, SQL Database will be more stable in this case.
You know most of SQL databases is supporting ACID. Mongdb has started to support ACID as well.
But when started to process huge number of transactions, SQL Database is still the preferable choice.
In this case, most of TO C(To Client) application is using SQL DB.
Note: Redis is another choice as well. We will talk about it in future articles.
3. Development efficiency
SQL Database need to define schema/tables first, later each column/name changes to table/schema need to manual update in database as well.
But NOSQL do not have to do this. Yo just need to save the data with the newer data format and store into the schema. NOSQL Database can still auto save it as it is freeform data.
This is most powerful use case of the NOSQL Database.
Using NOSQL database is definitely faster during POC(Proof of Concept) and MVP(Minimum Viable Project) development.
4 Potential Bug/defects
In most of cases, Flexibility comes with a price. When your data is unstructured and unverified, then it can has various issues.
So if you want your data has better strictness, NOSQL Database is not your preference
For example, you data need full validation during the backends process running. Then do not choose NOSQL Database.
Otherwise, you need to write custom logic in your frontend code to validate.
5. Speed of writing data to Database
NOSQL is faster. In SQL Database, natively it has default validation. This slow down a bit on the writing speed.
NOSQL Database can execute more write database operations per second compare to SQL Database.
6. Speed of reading data from Database
SQL Index can make faster when reading data from database. But some of the NOSQL DB has index as well. But it is different than the SQL index in SQL Database, it does not work as efficient as SQL Index.
7. Use cases
If you want to do POC(Proof of Concept) or prototype project, NOSQL db can be a good choice e.g, Mongdb.
NOSQL DB - Mongdb is more suitable to store configuration data. In most of cases, the configuration data is dynamic and also generally come with key-value data format. The read/write speed is much more faster than SQL Database.
If you have legacy code/system that already with structured data to be integrated with your application, then the SQL Database should be your preference.
Do not think NOSQL Database is most recent Database technology then to choose the Mongdb.
In most of cases, SQL Database can be the better choice.
It is all should be based on your use case and scenario to choose.
PS: The more latest technology is not always the best choice for your application.
Technology evaluation needs to choose the most suitable technology.