Difference between SQL and NoSQL
It is widely known that 80 percent of the world’s data is unstructured or semi-structured data, NoSQL concept has beceome more and more popular. This artical help you understand basic difference between SQL and NoSQL data and which database should you choose to use.
There are two important terminology you need to know.
ACID
ACID as shorthand for Atomicity, Consistency, Isolation, and Durability. These 4 are basic principle of SQL database. You can click on the above link of ACID to know more about the details.
In a simple usecase, a transfer of funds from one bank account to another, even involving multiple changes such as debiting one account and crediting another, is a single transaction. The transaction can be either successful or fail, And the state can only be from one valid status to another.
BASE
A BASE system gives up on consistency. – Basically available indicates that the system does guarantee availability, in terms of the CAP theorem. – Soft state indicates that the state of the system may change over time, even without input. This is because of the eventual consistency model. – Eventual consistency indicates that the system will become consistent over time, given that the system doesn’t receive input during that time.
Simple Example to explain
Eventual consistency:
- I watch the weather report and learn that it’s going to rain tomorrow.
- I tell you that it’s going to rain tomorrow.
- Your neighbor tells his wife that it’s going to be sunny tomorrow.
- You tell your neighbor that it is going to rain tomorrow.
Eventually, all of the servers (you, me, your neighbor) know the truth (that it’s going to rain tomorrow), but in the meantime the client (his wife) came away thinking it is going to be sunny, even though she asked after one or more of the servers (you and me) had a more up-to-date value.
As opposed to Strict Consistency / ACID compliance:
- Your bank balance is $50.
- You deposit $100.
- Your bank balance, queried from any ATM anywhere, is $150.
- Your daughter withdraws $40 with your ATM card.
- Your bank balance, queried from any ATM anywhere, is $110.
At no time can your balance reflect anything other than the actual sum of all of the transactions made on your account to that exact moment.
Reason to use a SQL DATABASE
Even as NoSQL databases gain popularity for their speed and scalability, there are still situations where a highly structured SQL database may be preferable. Here are a few reasons you might choose an SQL database:
- You need to ensure ACID compliancy ACID protects the integrity of your database by prescribing exactly how transactions interact with the database. Generally, NoSQL databases sacrifice ACID compliancy for flexibility and processing speed, but for many e-commerce and financial applications, an ACID-compliant database remains the preferred option.
- Your data is structured and unchanging If your business is not experiencing massive growth that would require more servers and you’re only working with data that’s consistent, then there may be no reason to use a system designed to support a variety of data types and high traffic volume.
REASONS TO USE A NOSQL DATABASE
When all of the other components of your server-side application are designed to be fast and seamless, NoSQL databases prevent data from being the bottleneck. Big data is the real NoSQL motivator here, doing things that traditional relational databases cannot.
- Storing large volumes of data that often have little to no structure. A NoSQL database sets no limits on the types of data you can store together, and allows you to add different new types as your needs change. With document-based databases, you can store data in one place without having to define what “types” of data those are in advance.
- Rapid development. If you’re developing within two-week Agile sprints, cranking out quick iterations, or needing to make frequent updates to the data structure without a lot of downtime between versions, a relational database will slow you down. NoSQL data doesn’t need to be prepped ahead of time.