SQL vs NoSQL: Choosing Database Design

SQL vs NoSQL: Choosing Database Design

Hello everyone! I have recently concluded my Let's Build A MySQL Node.Js CRUD App series and received a few questions regarding the difference between SQL and NoSQL databases. Thank you so much for enjoying the series and participating with questions.

In this article, I shall answer these questions by comparing relational and non-relational databases and determine when it's best to choose one over the other.

image.png

SQL vs. NoSQL: What are they

Both SQL and NoSQL Databases serve the same purpose - to store data. But they do have some differences between them.

First, SQL stands for Structured Query Language. It is a language used to retrieve and manipulate data in relational databases. A relational database is a type of database that uses predefined schemas and tables, making it very structured.

Unlike SQL (relational) databases, NoSQL or non-relational databases store data in unstructured formats. Instead of tables, NoSQL databases can come in various forms such as JSON (document-based), key-value pairs, graphs and dynamic-sized tables.

image.png

When to use

Because of their difference in the way they store data, it is important to understand when to use one over the other. Let's look at a few factors to consider.

1. Scaling

SQL databases can be vertically scaled, which means that as the load increases, it can be migrated to a larger server with more RAM, CPU or SSD to handle excess capacity. A single server will have to be continuously scaled up as the database capacity increases.

On the other hand, due to their flexible structure, NoSQL databases can be horizontally scaled. This means that excess load can be shared and handled by adding more servers instead of scaling up a single server.

image.png

Hence, NoSQL databases can infinitely scale, making them useful for Big Data storage. Companies like Google, Amazon and Facebook developed their own NoSQL databases as they could no longer vertically scale their relational databases over time.

2. Schema

As we've discussed before, SQL databases stores structured and organized data into tables while NoSQL typically does not.

This makes SQL databases useful for data with multi-row transactions and relational structures such as accounting or legacy systems.

NoSQL databases are less rigid, so they can used for any type of data that does not rely heavily on relational structures. They are best used for hierarchical data structures.

3. Technologies

They are plenty of choices to choose from when it comes to both SQL and NoSQL databases. Here are some examples:

SQL Databases:

  • MySQL
  • PostgreSQL
  • Oracle
  • Microsoft SQL Server

NoSQL Databases:

  • MongoDB Atlas
  • Cassandra
  • HBase
  • Redis
  • Amazon DynamoDB

4. Standardized Language

SQL databases use SQL to make complex queries in order to retrieve or manipulate data. SQL is a widely used and easy to learn language that even non-programming people have used. The standardization of SQL across all SQL databases makes it an accessible platform for anyone to learn and use.

NoSQL databases are not suitable for complex queries because each data is stored and used in different ways. Its unstructured schema makes it difficult to have a standardized method/language that can make complex queries and stay uniform across all databases.

So to Recap...

SQLNoSQL
DataStructured, using tables and predefined schemasUnstructured, flexible data types and format
Best UseData with complex relational structuresAny data structure that needs flexibility or has hierarchy
ScalingVerticalHorizontal
LanguageStandardizedNot Standardized
ExamplesMySQL, PostgreSQL, Oracle, Microsoft SQL ServerMongoDB, Cassandra, HBase, Redis, Amazon DynamoDB

These are some key differences between SQL and NoSQL. I hope it helps in determining which type of databases suits your needs. Thanks for reading and cheers!

Did you find this article valuable?

Support Victoria Lo by becoming a sponsor. Any amount is appreciated!

ย