Q: NoSQL? A: No Problem!

Joseph Harwood
4 min readOct 11, 2019

--

Solid reference.

Most programmers are familiar with SQL (Structured Query Language) and Database Management Systems (DBMS) like PostgreSQL, SQL Server, Oracle, MongoDB, MariaDB, Redis, and MySQL. What you may not know is that these DBMS’s are either Relational or Non-Relational. This blog post will explore the differences between these 2 types with examples.

Relational Databases

Most databases in the past were relational databases, meaning they used a set data structure, which allowed them to link information from different tables, using indexes, that could then be linked through a relationship. A relationship example would be an Owner table that has many pets in a Pets table. SQL (Structured Query Language) is the language used to create, retrieve, update, and delete information stored in the tables. The popular examples are PostgreSQL, SQL Server, Oracle, and MariaDB.

Non-Relational Databases

NoSQL is exactly how it sounds, it is “No Structured Query Language”. Meaning that is a non-relational database that doesn’t use any kind of relational enforcement. You decide whether or not any relationships are necessary.

Real World Uses

A SQL database is ideal for an application that requires complex, intensive queries between different databases and vertical scaling, like an online shopping system. Vertical scaling is adding more power to an existing table, like adding more owners to an Owners table and pets to a Pets table.

A NoSQL database is typically better for applications that require horizontal scaling and more flexible architecture, such as big data analytics and real-time web applications. Horizontal scaling is adding or removing more nodes to a system, such as adding a new computer to a distributed software application. An example would be scaling out from one web server to three, where a relationship might not be necessary.

Architectural Differences

Relational databases uses tables that have schemas that strictly define the structure of the tablespaces, tables, indexes, and table relationships. I feel like most programmers understand relational databases, so I want to focus on non-relational databases in this post. Non-relational databases don’t have schemas and data is kept in key-value pairs, columns, documents, or graphs. Let’s break down what some of these are.

Inside the database, there is a collection. Inside of a collection, there a document, and inside the document, there are key-value pairs. From a relational database perspective, a collection is a table, the document is a row, and row consists of key-value pairs. Records are stored in JSON in a non-relational database.

JSON/NoSQL  
{
"Book id": "1",
"Book title": "A Clockwork Orange",
"Author id": "23",
"Author name": "Anthony Burgess"
}

Key-value pairs should be familiar to everyone that has used Javascript and JSON. A key in the key-value pair must be unique, and it allows you to access the value associated with the key. Redis, Riak, and Oracle NoSQL are key-value databases.

A document database is a non-relational database used to store the semi-structured data as documents in JSON format. A document can have the same or a different data structure to other documents. Documents are grouped into collections (like tables in relational databases). This allows you to persist the data in a database by using the same model that you use in your application JSON code. Apache, CouchDB, and MongoDB are document databases.

Graph, in-memory, and search non-relational databases aren’t used in the most popular non-relational databases, like MongoDB and Redis, so I won’t discuss these today. Feel free to look these up if they interest you.

I hope that this introduction to NoSQL will inspire you to try it out in a project!

Sources

https://ormuco.com/blog/most-popular-databases

https://www.javatpoint.com/aws-non-relational-database

--

--

No responses yet