When it comes to choosing a database for a project, I usually go for NoSQL because using it with NodeJs is very simple in my opinion. So I have had this thought to research on what must influence my decision to choose either Relational or Non-Relational Database systems. Finally, I got to know there is a great theorem behind this.
Today, I would like to share with you the C.A.P theorem.
CAP stands for:
Consistency ( all nodes see the same data at the same time)
Availability (a guarantee that every request receives a response about whether it was successful or failed)
Partition tolerance (the system continues to operate despite arbitrary message loss or failure of part of the system)
The CAP theorem, also known as Brewer's theorem, states that it is impossible for a distributed computer system to provide all above-listed features at the same.
Though database systems cannot have all three but can have any two of them.
SQL databases employ CA while NoSQL databases use AP from C.A.P. So depending on the type of an application you are building, knowing this concept will help you a lot in choosing the right database system.
For instance, if you are working on an application where you want an update to be seen by users of the application without a second or minute delay among any of them then consistency matters In such an application, distributed system with consistency holds. Therefore SQL database system will be used in this case.
The main takeaway from this little piece is knowing whether your application needs CA or AP from CAP is very important and will help influence your decision to choose the right database system.