What is NoSQL

Ranjula Madushan
6 min readApr 27, 2021

The use of a SQL or NoSQL database to store data is one of the most fundamental decisions to make when creating an application. Traditional SQL (relational) databases are the product of decades of technological advancements, best practices, and real-world stress testing. One of the most important decisions to make when developing an application is whether to use a SQL or NoSQL database to store data. Traditional SQL (relational) databases are the product of decades of technical advances, best practices, and stress testing in real-world scenarios.

As a result of these limitations, NoSQL databases emerged. NoSQL databases store and handle data in a way that allows developers to work quickly and with a lot of flexibility. Many were created by companies such as Google, Amazon, Yahoo, and Facebook, who were looking for better ways to store and process data for large websites. Many NoSQL databases can be scaled horizontally across hundreds or thousands of servers, unlike SQL databases.

However, the benefits of NoSQL do not come without a price. Data accuracy is not always as high in NoSQL systems as it is in SQL databases. Although SQL databases have historically sacrificed efficiency and scalability for the ACID properties that underpin secure transactions, NoSQL databases have increasingly abandoned those ACID guarantees in favour of speed and scalability.

To summarize, SQL and NoSQL databases have different trade-offs. Although they can compete in the sense of a particular project — for example, which to use for this or that application — in the big picture, they are complementary. Each is best suited to a specific use case. It’s not so much an either/or situation as it is a matter of which tool is best for the job.

NoSQL vs SQL

The basic distinction between SQL and NoSQL is straightforward. Everyone has its own ideology about data storage and retrieval.

All data in SQL databases has an underlying structure. A schema is a structured description of how data inserted into a database would be composed in a traditional database like Microsoft SQL Server, MySQL, or Oracle Database. For example, a table column may be restricted to integers only. As a consequence, the information stored in the column would be highly normalized.

Data can be stored in a schema-less or free-form fashion with NoSQL. In any record, any data can be stored. There are four common models for storing data in NoSQL databases, which lead to four common types of NoSQL systems:

  1. 1. Document databases. ( eg: CouchDB, MongoDB): Inserted data is saved as free-form JSON structures or “documents,” with the data ranging from integers to strings to free-form text. There is no need to specify which fields, if any, will be included in a text.
  2. 1. Key-value stores. ( eg: Redis, Riak ) : Keys are used to access free-form values in the database, which may range from simple integers or strings to complex JSON documents.
  3. 1. Wide column stores(eg: HBase, Cassandra). In contrast to a traditional SQL scheme, data is stored in columns rather than rows. For queries or data views, any number of columns (and thus several different types of data) can be grouped or aggregated as required.
  4. 1. Graph databases(eg: Neo4j). Each node in the graph represents a free-form chunk of data, and the data is represented as a network or graph of entities and their relationships.

Schema-less data storage is useful in the following scenarios:

  1. 1. You want quick access to the data, and you care more about speed and ease of use than secure transactions or accuracy.
  2. 1. You’re storing a huge amount of data and don’t want to lock yourself into a schema because modifying it later would be time-consuming and painful.
  3. 1. You’re importing unstructured data from one or more outlets, and you’d like to keep it in its original format for maximum flexibility.
  4. 1. You want to store data in a hierarchical structure, but you don’t want to rely on an external schema to explain those hierarchies. NoSQL enables data to be casually self-referential in ways that SQL databases find more difficult to imitate.

Querying NoSQL databases

Traditional databases use the Structured Query Language (SQL) to communicate with the server when storing and retrieving data. Although individual databases can handle such operations differently (for example, window functions), the fundamentals of SQL remain the same.

Each NoSQL database, on the other hand, appears to have its own querying and data management syntax. For example, CouchDB creates and retrieves documents from its database using JSON requests sent over HTTP. MongoDB uses a binary protocol to send JSON objects via a command-line interface or a language library.

Some NoSQL products can work with data using SQL-like syntax, but only to a limited extent. The column store database Apache Cassandra, for example, has its own SQL-like language, the Cassandra Query Language or CQL. The SELECT and INSERT keywords, for example, are straight out of the SQL playbook in CQL. In Cassandra, however, there is no way to perform a JOIN or subquery, so the relevant keywords aren’t available.

Shared-nothing architecture

A “shared-nothing” architecture is a popular design option in NoSQL systems. Each server node in the cluster operates independently of the others in a shared-nothing architecture. To return a piece of data to a client, the machine does not need to obtain consensus from every single node. Queries are fast since they can be answered by the closest or most convenient node.

Resiliency and scale-out are two more benefits of shared-nothing. It’s as simple as spinning up new nodes in the cluster and waiting for them to coordinate with the others to scale out the cluster. If a NoSQL node fails, the cluster’s other servers will continue to work. Even if fewer nodes are available to serve requests, all data remains accessible.

It’s worth noting that a shared-nothing architecture isn’t exclusive to NoSQL databases. Many traditional SQL systems can be set up in a shared-nothing fashion, but this usually means sacrificing cluster consistency for results.

NoSQL limitations

Why not leave SQL completely if NoSQL offers too much freedom and flexibility? The short answer is that SQL databases still provide the constraints, consistency, and protections that many applications need. In such instances, some of NoSQL’s “advantages” can become disadvantages. Other drawbacks stem from the fact that NoSQL databases are still in their infancy.

No schema

Even if you’re working with free-form info, you’ll almost always need to constrain it to make it usable. Imposing constraints in NoSQL means transferring control from the database to the application developer. An object relational mapping method, or ORM, for example, may be used to enforce structure. However, NoSQL does not usually allow the schema to live alongside the data.

Optional data typing and validation mechanisms are available in some NoSQL solutions. For example, Apache Cassandra has a number of native data types that are similar to those found in traditional SQL.

--

--