SQL vs NoSQL: What’s The Difference?
I’ve been building an app with the MERN stack and this is my first time using a NoSQL database like MongoDB, It is quite different from my experience with SQL databases such as PostgreS and SQLite and in today’s article I will be breaking down the key differences and what are my thoughts on these database platforms.
SQL databases are the traditional way to use a Structured Query Language to create a schema table for inputing and manipulating relational data. In case you haven’t read my previous blog, it’s been one year since my programming journey and for the most part I’ve been using SQL for the past year to handle data in my apps and specifically PostGreSQL databases ran on Ruby on Rails backend servers.
- Due to having a predefined schema table, data can be accessed really fast because we would know exactly what row or column to manipulate any data.
- Been in use with programming for decades, which offers great community knowledge and support.
- SQL follows the ACID properties making the data very accurate and easy to navigate in the DB.
- It has drawbacks with scaling, since you would have to redefine the database scheme if you want to add something simple such as a user’s favorite color or some other random data that you might have to assign in the future.
- Can be troublesome converting data objects with correct data due to placement of database rows & columns
- Just not very user friendly in my opinion, SQL as a language wasn’t too hard to learn but the clunky interfaces that DB companies offers, are just not very good.
NoSQL databases come around during the mid-late 2000s and are more flexible and modern and can be made with less structure for assigning data. There are different types of NoSQL database, it can be column based, graph based or document based which is what I’ve been using with MongoDB in conjunction with a Node Express server.
- Great with scaling, due to being able to create and manipulate data freely in an unstructured way thus being able to add more attributes to data along the way.
- You can start creating a database without having to predefine a scheme structure, which is great in my opinion.
- Very flexible since it isn’t confined by rows or column, NoSQL store data in “documents” which each can have it’s own properties and attributes.
- Not great for complicated queries since the document format is less structured compared to traditional SQL schema tables.
- NoSQL is becoming more and more popular these days but it still lacks the community support that SQL can offer due to years in practice.
- Can become costly once it scales and the file system becomes too big if you aren’t properly handling the duplication of data.
When to use each
Both SQL and NoSQL are great and come with their own pros and cons. I personally prefer using MongoDB at the moment due to it’s flexibility and scalability but I would go back to a SQL database if I’m building some sort of app with a more advanced complex query for data, SQL relational schemas can be annoying to build out but once it’s done, it offers great speed through structure.
NoSQL are becoming more and more standardized these days and I’m really enjoying MongoDB but just keep in mind of what type of app you want to build and you will have a great time down the line.
Thank you for reading and please leave a comment if you‘ve enjoyed and follow for more coding and tech content.