SQL & NoSQL

A beginner-friendly explanation of how computers process information — from binary and bytes to how text, images, videos, and audio are represented and stored.

2025-12-31

Mongo DB V1 Engine Architecture

SQL vs NoSQL — My General Understanding

All right, so let’s talk about SQL and NoSQL in general.


Early Databases and SQL

From the 90s — or even before the 90s — when databases came after file systems, we started working with data in a tabular format, like rows and columns.

To query this data, we used Structured Query Language (SQL). This model continued and evolved through the 2000s.

So basically, data was stored in tables, and we queried it using SQL.


Problem with Mapping JSON to Tables

After the 2000s, people started thinking differently.

Most applications just wanted to read and write data, and that data was usually in JSON format. The frontend sends JSON, the backend receives JSON, but then we had to map that JSON into rows and columns.

That mapping was honestly hard and sometimes unnecessary.

So people thought:

Why not store JSON directly in the database itself?


Why NoSQL Came Into the Picture

At a low level, databases already store data like this:

  • Data is converted into bytes
  • Bytes are stored inside pages
  • Pages can contain multiple records

In SQL:

  • Rows are stored as records inside pages

So the question was:

If rows can be stored as records, why can’t JSON be stored as records as well?

Why not just store JSON in byte format directly?

That’s where the idea of NoSQL came in.


How NoSQL Works (At a High Level)

So what generally happens is this:

  • We have JSON data (for example, form data)
  • Frontend sends JSON to the backend
  • Backend sends JSON to the database

Now what the database engine does is:

  • Converts JSON into Binary JSON
  • Stores that Binary JSON in a page
  • Each page can have multiple records
  • Each record contains the JSON payload and metadata

And that’s basically how NoSQL document databases work.

This is the core difference.


SQL vs NoSQL — Storage Model

Now let’s talk clearly about SQL and NoSQL.

SQL

  • Data is stored in a structured format
  • Tables with rows and columns
  • Examples:
    • PostgreSQL
    • MySQL
    • Oracle

NoSQL

  • Data can be stored in JSON-like structures
  • Different models exist:
    • Document storage (MongoDB)
      • Each document is a JSON
    • Key-value storage
      • Entire JSON stored as a value
      • Used commonly for cache
      • Example: Redis
    • Other examples:
      • MongoDB
      • Firebase

This is the second major difference.


When to Use SQL

SQL is generally used when consistency is needed.

By consistency, I mean:

  • Database-level constraints
  • Check constraints (for example: value must be greater than 80)
  • Strong guarantees on data correctness

I’m talking at a general SQL vs NoSQL concept level, not about specific databases.

Some people may argue that MongoDB supports constraints after version 4.0 — that’s true — but that’s a separate discussion.

At a general level:

  • SQL databases have strong constraints
  • They ensure higher consistency and durability

That’s why SQL is used in:

  • Banking systems
  • Financial applications
  • Medical systems

SQL for Relational Data

SQL is also preferred when:

  • Data is highly relational
  • You need joins
  • You need aggregations
  • You want to query across multiple tables

And obviously:

  • When you need a strict schema

That’s the main use case of SQL.


When to Use NoSQL

NoSQL shines when:

  • You have huge amounts of data
  • Data is distributed across multiple servers
  • Servers are spread across different regions or continents

In SQL:

  • You generally rely on a central database server

In NoSQL:

  • You can scale horizontally
  • Data can be distributed across nodes

Flexible Schema Use Case

NoSQL is also useful when schema needs to be flexible.

For example:

  • Today, a user profile supports a GitHub URL
  • Tomorrow, a new platform appears
  • Later, more profile links are added

In SQL:

  • You need schema migrations

In NoSQL:

  • You can just add new fields
  • No fixed schema
  • Backward compatibility is naturally supported

Caching and Fast Data Access

For small, frequent data access:

  • Cache systems are used
  • NoSQL databases like Redis work very well

So NoSQL is also used for:

  • Caching
  • Session storage
  • Fast lookups

Final Summary

So overall:

  • SQL is best when:

    • Strong consistency is required
    • Data is relational
    • Schema must be strict
    • Joins and complex queries are needed
  • NoSQL is best when:

    • Data is large and distributed
    • Horizontal scaling is required
    • Schema needs to be flexible
    • Fast reads or caching is needed

That’s majorly how SQL and NoSQL work at a general level.

I’ve also given some examples here.

And if there is any doubt, please let me know.

Conclusion & Summary

Here's a quick overview of the topics we covered in this post:

SQL vs NoSQL — My General Understanding

Early Databases and SQL

Problem with Mapping JSON to Tables

Why NoSQL Came Into the Picture

How NoSQL Works (At a High Level)

SQL vs NoSQL — Storage Model

SQL

NoSQL

When to Use SQL

SQL for Relational Data

When to Use NoSQL

Flexible Schema Use Case

Caching and Fast Data Access

Final Summary

built by harsh ↗