NoSQL vs Relational Database
NoSQL vs Relational Database
If you are already working in the analytics domain then you might have heard words like PostgreSQL, MongoDB, MySQL, Oracle, etc. We also do have a fair bit of idea about the fact that we store our tables and databases in these places. But why can’t we have everything under one hood?
We should have heard people saying that ABC is a NoSQL database and we should store these data in it rather than a traditional Relational database, what does that mean?
Does NoSQL mean that you don’t have to write SQL on top of it? If yes, then what is the use?
Let’s try to understand NoSQL vs Relational Database
NoSQL stands for Not Only SQL
Not Only SQL – Every item in the database stands on its own
Relational databases are like predefined table structures where you can surely add as many rows as possible but adding a new column is a pain as you have to change the schema of the table, thus it is a vertically scaling database. Whereas NoSQL is built in such a way that you can add any number of rows but at the same time you can add any additional information pertaining to a row.
Example – Suppose you have an employee table and you have a NoSQL database, in this table, there will be only 2 columns i.e. a primary key and a values column where you can add as many details as possible, for one employee you can add only name and phone number whereas for another employee you can add the complete profile ranging from name to spouse’s work status, how?
In general, the value thing is stored in a JSON format which again is a key-value pair and you can add any number of attributes corresponding to an employe
Relational Database – Vertical scaling Ex. PostgreSQL, SQLite, MySql
NoSQL – Vertical and Horizontal scaling – Each item in the database only has two things – unique key and values
Different formates in which you can store data in your NoSQL database
1. Document Database – JSON
2. Key-Value store
3. Graphical database
How does this scaling makes database life easier?
As discussed, Scaling in NoSQL can work in a horizontal way
Let’s take an example – A company XYZ runs a NoSQL database which has 10000 servers, All these servers work as a partition i.e. your data which you want to fetch is not present in only one server, it can be present in any partition.
Won’t it be too cumbersome for the database to check all the partition to find a detail ?How do find where is the data stored?
NoSQL databases are key-value stores
It’s not just a key-value pair – It is a key-hash-value where each key is associated with a hash value and this hash value works as a partition identifier 😛
Suppose the hash value is in the range of 0 to 1000 and all your data is stored in one DB. Now, if you want to double your DB performance, you can add another server, and now
Server 1 – Hash value 0 to 500
Server 2 – Hash value 501 to 1000
This range of 0 to 1000 is called a keyspace. Keyspace tells you where to store new items and where to find the existing ones.
NoSQL is schemaless – anyways you are storing everything in a JSON format and you can increase or decrease the amount of information in each field. In a relational database, you have to define the schema of the table and have to adhere to it
Example of NoSQL –
AWS – DynamoDB
Google Cloud – Big Table
Azure – CosmoDB
You can also run NoSQL DB yourself by using software like Cassandra, CouchDB, MongoDB.
We will try to create a video on the same to give a glimpse of what is JSON and NoSQL
Some Useful resources for SQL and Python interview questions
Flipkart Interview Question – How to get all the rows with NULLs from multiple columns – Solved with 3 different ways –
How SQL Query is executed at the back end –
Understand the concept of cumulative sum in SQL – One of the most asked concepts
Myntra SQL interview question (Very important concept) – https://www.youtube.com/watch?v=wor2osrIjzc
Most asked SQL concept asked in almost all the product based companies interview – https://www.youtube.com/watch?v=aqpkrJvvqxs&t=4s
If you are wondering how to make a career in the Analytics domain, then our 10 e-book bundle with 1400+ direct interview questions are for you – Check out our booklist