Article Banner Image

SQL vs NoSQL

When comparing SQL and NoSQL it’s important to know that these two are very different types of databases languages which are equally useful in their own right—but for contrasting reasons and use-cases. It is not in competition with each other that one is better than other, moreover, they are meant to be used for different purposes & use cases. The intent of this article is to describe what SQL is, what a NoSQL is and then conclude with a summary of the properties for each of these types in an effort to help you decide which best suits your needs.

 

1.SQL 

Structured Query language (SQL) is a standard database language. It is used to create data, maintain data and retrieve data from a relational database. A relational database is a collection of data objects/elements that have pre-defined relationships. These relations are organised in a table format with rows and columns. The tables store data about objects that will be represented in the database. The actual value of an attribute is represented in a field, while each column in a table represents a specific type of data. Each row indicates a group of linked values for a single item or entity. Each table has a unique identifier named the primary key and a foreign key which is used to link rows from another table. 

A few examples of relational databases are 

MySql,

Oracle,

SQL Server,

Postgres, etc.. 

SQL is used to write complex queries but on the other side, it can be restrictive too. As mentioned above SQL has a particular structure and all the data must follow the same structure. This means a significant change later in the data be disruptive to the system. If a user wants to scale its SQL database, the user can scale it vertically. Vertically scaling means you can increase the load on a given server by increasing its RAM, CPU or SSD. SQL databases follow ACID properties.

 

ACID stands for Atomicity, Consistency, Isolation and Durability. 

Atomicity: Every item is atomic it is all or nothing. 

Consistency: Data needs to be consistent in each table. 

Isolation: Every database transaction is run in its own space. One transaction at a time. 

Durability: What's written stays written. 

 

2.NoSQL

“Necessity is the Mother of Invention!” that was the case for the NoSQL database. NoSQL database was developed by huge internet companies like Google, Amazon and Yahoo. They developed this database as the relational database couldn’t cope with the increasing data processing requirements. Some of the databases don’t have a fixed structure to store data, and therefore, they do not use SQL. These databases are called NoSQL databases. A few examples of not relational databases are MongoDB, DynamoDB, Cassandra, etc., As NoSQL databases are not relational, they use other methods to store data. These methods can either be key-value pairs, document-based, graph databases or wide-column stores. This flexibility signifies that documents can be created without a defined structure first. In future, if the desired application needs to scale up, the user can scale the application horizontally. Horizontally scaling is basically adding more servers to your database instead of increasing RAM, CPU or SSD on one server. NoSQL databases do not follow the ACID properties, but they follow the CAP properties.

 

CAP stands for (Consistency, Availability and Partition).

Consistency: every read receives the most recent write or an error.

• Availability: every request receives a (non-error) response, without the guarantee that it contains the most recent write.

• Partition: the system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes. It is impossible for a NoSQL database to guarantee all three CAP properties. The common factor in all the NoSQL database properties is. P of partition. Partition is necessary else the database won’t be available most of the time. For this reason, most of the databases are divided into two parts CP and AP. 

 

  • Databases that use APO Properties: 

a) Cassandra DB: “Apache Cassandra is an open-source NoSQL distributed database trusted by thousands of companies for scalability and high availability without compromising performance. Linear scalability and proven fault tolerance on commodity hardware or cloud infrastructure make it the perfect platform for mission-critical data.” https://cassandra.apache.org/_/index.html

 

b) Couch DB: “Apache CouchDB is an open-source document-oriented NoSQL database, implemented in Erlang. CouchDB uses multiple formats and protocols to store, transfer, and process its data. It uses JSON to store data, JavaScript as its query language using MapReduce, and HTTP for an API.” - https://en.wikipedia.org/wiki/Apache_CouchDB 

 

 

  • Databases that use CAP Properties: 

a) Mongo DB: “MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License” -https://en.wikipedia.org/wiki/MongoDB

 

b) HBase: “HBase is an open-source non-relational distributed database modeled after Google's Bigtableand written in Java. It is developed as part of Apache Software Foundation's Apache Hadoop project and runs on top of HDFS or Alluxio, providing Bigtable-like capabilities for Hadoop.”- https://en.wikipedia.org/wiki/Apache_HBase 

 

SQL can be best used for money transactions. Where a guarantee is necessary. NoSQL can best be used for social media platforms where a guarantee is not that necessary. The current problem that we face is scalability and the client has explicitly told us to make use of microservices. For this reason, the most suitable database solution is the NoSQL database. In NoSQL databases, there are many options to choose from. Some of the databases give more value to CP properties than AP. For that reason, we need to analyse what is the best outcome for this problem. 

 

So, which should you choose for your project?  For the answer to this question, we can circle back to the beginning of this article.  In short, there is no single right answer. The best way to determine which one is best for your project is to analyze the organization’s needs and application functionality you need to achieve. If you get stuck in your project & need help, experts at Zerovaega Technologies will contribute to your problem statement.

Connect with us today for a digital transformation of your business! 

RELATED ARTICLES

POPULAR ARTICLES

LATEST ARTICLES