Data StorageNoSQL Vs Relational

The two most common types of databases are relational databases (SQL) and NoSQL databases. Both have their pros and cons. Almost every system design problem requires you to implement a database so it's important to understand the difference

Relational

SQL databases are the most common type of relational database. They store data in tables, and each table has a defined schema that dictates the structure of the data within that table. SQL databases are easy to query and are well suited for projects that require complex queries or transactions. However, they can be more difficult to scale than NoSQL databases.

NoSQL

NoSQL databases, on the other hand, do not have a defined schema. This makes them more flexible but also more difficult to query. NoSQL databases are well suited for projects that require high scalability or real-time data access. However, they can be more difficult to manage than SQL databases. 

Choosing between them

If your project requires complex queries or transactions, then an SQL database is probably your best bet. If your project requires high scalability or real-time data access, then a NoSQL database is probably a better choice. You can scale relational databases as well but they result in more complicated systems.

How to approach during the interview

Ultimately, it's important to understand the difference between these two types of databases so that you can make an informed decision about which one is right for your project. If you are stuck during your interview, a good technique is to default to NoSQL unless you have to make complex queries on your data.

Breakdown of NoSQL Databases

Advantages

  • Schema-less: Data can be added without having to first define a schema. This makes NoSQL databases much more flexible than relational databases. 
  • Horizontally scalable: It's easy to add more nodes to a NoSQL database cluster since there is no need to maintain relationships between data items. 
  • High performance: NoSQL databases can handle large volumes of data and high traffic loads very well.

Disadvantages

  • Difficult to query: Since data is not stored in a traditional table format, it can be difficult to query NoSQL databases. 
  • Lack of transactions: Most NoSQL databases do not support transactions, which means that if you need ACID compliance you will need to use a different type of database. 
  • Limited functionality: NoSQL databases often have limited functionality when compared to relational databases. For example, they may not support features such as joins or aggregations.

Breakdown of Relational Databases

Advantages of Relational Databases: 

  • Easy to query: Since data is stored in tables, it is easy to query relational databases using SQL. 
  • Support for transactions: Most relational database management systems support transactions, which means that you can ensure data consistency even if multiple users are updating the same data simultaneously. 
  • Rich set of features: Relational databases offer a rich set of features such as joins, aggregations, and stored procedures. 

Disadvantages of Relational Databases:

  • Requires a schema: You must first define a schema before you can start adding data to a relational database. This can be time-consuming and limits flexibility. 
  • Not horizontally scalable: It's difficult to add more nodes to a relational database cluster since data must be partitioned across nodes based on relationships between items. 

Related Problems