What is NoSQL?

What is NoSQL?
Photo by domoskanonos/ Canva

NoSQL has been on my backlog of things to learn. It’s covered in a heavy layer of dust because it’s been there for that long! When I was writing the blog on SQL, I was reminded of it. I’ve been researching and binging on NoSQL content for the last couple of weeks. I’m going to share with you what I’ve learned.

I’d encountered many foreign terminologies and concepts. I went down many rabbit holes and chased many hyperlinks to find answers to patch my knowledge gap. So, here is what I’ve got to share:

  • What is NoSQL and NoSQL database?
  • Brief history on NoSQL databases
  • Advantages vs Disadvantages of NoSQL
  • Types of NoSQL database

What is NoSQL and NoSQL database?

My first impression of NoSQL is that it’s another language, like SQL, and I thought the name was rather odd. I wondered if whoever coined the term NoSQL was poking fun at SQL.

My thinking was off course. The term “NoSQL” stands for “non SQL” or “not only SQL”. NoSQL is not a language; rather, it is an approach to database management that can accommodate diverse data models, which means it’s flexible. When people use the term “NoSQL database”, they typically refer to any non-relational database, i.e., databases that store data in a format other than relational tables.

NoSQL databases are great for modern applications such as mobile, web, and gaming that require flexible, scalable, and fast performance where subpar user experiences are unacceptable.

Brief History on NoSQL databases

NoSQL databases appeared in the late 2000s as a culmination of these elements that were occurring at the time:
• a dramatic decrease in storage cost,
• accelerated growth in the amount of data that applications need to store and query data, and
• a rise in popularity of the Agile Manifesto for Software Development drove the need for the ability to iterate quickly and make changes throughout their software stack, which includes down to the database.

NoSQL databases allow developers to store immense amounts of data of all forms (structured, semi-structured and unstructured) and sizes, giving them a lot of flexibility.

Advantages and Disadvantages of NoSQL

Advantages

NoSQL databases are not just one type of database. There are a few, and each has its unique features. So, the advantages provided here are at a high level:

Flexibility: NoSQL databases are highly flexible, so they can store and combine any type of data, both structured and unstructured. Unlike relational databases, which can only store data in a structured way.

Elastic Scalability: Scalability is a system’s ability to increase or decrease performance in response to changes in processing demands. NoSQL databases allow you to scale to accommodate data growth while keeping costs low. NoSQL databases do this by scaling out (horizontal scale) instead of scaling up in a relational database. With scaling out, you’re adding more hardware. With scaling up, you’re adding more computing powers. A toaster analogy might help you understand this better. A typical toaster has two slots. If I’m making lunch for myself, I will toast two slices of bread, which would be done quickly. If I’m making lunch for 4 people, I would have to do this four times. Because I don’t particularly appreciate waiting, I could scale by buying a toaster with 8 slots or buying 3 more 2-slot toasters. The 8-slot toaster is scaling up, and the 4 2-slot toasters is scaling out.

High performance: NoSQL databases are designed for specific use cases, and this enables faster performance because you’re not trying to accomplish similar functionality with relational databases.

Disadvantages

Here are the drawbacks of NoSQL:

Lack of standardization: there is no standard for querying and managing data as each NoSQL database has its own syntax.

Lack of Consistency: NoSQL prioritizes scalability and performance over the consistency of the data. For example, if I was to enter the same information in a relational database, it’ll throw me an error because it won’t allow duplication in databases. While in a NoSQL database, it won’t; it’ll gladly accept the duplicate set of entries.

Types of NoSQL database

There are four major types of NoSQL databases: wide-column stores, document databases, key-value databases, and graph databases.

Wide-column stores

It stores data in familiar tables, columns, and rows just like relational databases tables. However, unlike relational databases, column names and formatting can differ from row to row in a single table. Typical uses of this type of database include internet search and event logging.

Document databases

These store data in a document. Each document contains pairs of keys and values. The values can typically be a variety of data types like strings, numbers, booleans (true(1)/false(0)), array, or objects. A group of documents is known as a collection. Here is an example of a document code:
Blog-15--Document1
This is a code of a to-do stored in a document. I can create another document for another item by repeating the code like so:
Blog-15--Document2
I can keep building it to form a to-do list. Note that each item is stored in a separate document.

This type of database is commonly used for content management.

Key-value databases

These use a simple key-value pair to store data. The key serves as a unique identifier.

Below is a screen grab from a NoSQL Database tutorial (by freeCodeCamp) I took. It is an image of CQL Console in DataStax Astra DB displaying retried key-value pairs from the “shop_inventory” table.
CQL (Cassandra Query Language) is a language just like SQL. It’s very similar to SQL, according to the course instructor.

Shopping-cart on an e-commerce site is an application that utilizes key-value databases.

Blog-15--Key-Value

Graph Databases

These store data in nodes and edges. Nodes are similar to rows in a relational database and typically store information about people, places and things. Edges represent relationships between the nodes. Graph database systems are applied in systems that require mapping relationships, such as social media platforms.

This image is another screengrab I’ve taken from the freeCodeCamp tutorial. It’s a graphical output of the graph database. The lines are the edges, and pictures of the monster, human, and god are your nodes.

Blog-15--Graphical-Database

If you are interested in diving deeper into NoSQL, I recommend you check out the tutorial I took by freeCodeCamp: NoSQL Database Tutorial- Full Course for Beginners. It’s 3 hours long, but you can stop at about halfway (~1:23) if you’re just after a theoretical understanding. The remaining video takes you through projects.