SQL vs NoSQL

Elijah Koulaxis

April 29, 2025

sql-vs-nosql

If you’ve ever found yourself comparing SQL vs NoSQL, welcome to one of the oldest and most practical debates in backend engineering. But let’s not just scratch the surface. Let's go deep. Like, how-data-is-written-to-disk deep.


The Schema

Let’s start at the surface level.

SQL (Structured Query Language) databases, like PostgreSQL, MySQL, and SQLite, looooooooove structure. You define tables, rows, columns, and data types. You get foreign keys, constraints, joins, and ACID transactions (we will explain what ACID is shortly).

On the other side, we have NoSQL (Not Only SQL) databases like MongoDB, Redis, Cassandra, and DynamoDB. These are more flexible, some store documents, some are key-value stores, others are wide-column or graph databases.

In short:


Let’s Talk Disk — Where the Magic (or Bottleneck) Happens

You click a button in your app, and that ends up in a database write or read. But what actually happens?

Writes: SQL vs NoSQL at the Metal (literally) Level

SQL databases typically follow a multi-step process when you insert or update data:

  1. First, they write to a WAL (Write-Ahead Log) a simple, sequential file. It’s fast, because sequential disk writes are way more efficient than random ones
  2. Then, they update in-memory buffers (think: RAM-resident versions of your tables)
  3. Later, they flush those buffers to the actual database files on disk, the “real” storage

Why this dance? Because it makes sure that even if the server crashes halfway, the WAL can replay what happened and restore everything. That’s the D in ACID: Durability

NoSQL databases on the other hand, play by different rules, favoring speed and availability over strict consistency. They often use eventual consistency, meaning they’ll respond to the client before the data is fully persisted:


Reading Between the Bytes

When it comes to reading data, things get a little more interesting, especially with how each database handles lookups.

SQL databases rely on indexes to quickly locate data. The most common index structure is the B-tree (or B+ tree). These are balanced trees, meaning the data is kept sorted. When you need to search for something, a logarithmic search (O(log n)) is performed, which means it’s super efficient. The best part? B-trees are designed to minimize disk seeks. When a node in the tree is accessed, the database loads a block of data into memory, which reduces the need for slow, random disk access. This is key to improving read performance.

Now, NoSQL databases have their own indexing strategies, and they vary based on the database engine, for example, Cassandra goes for a more write-heavy approach with Log-Structured Merge Trees (LSM Trees). These allow fast writes (since data is appended to logs), but the flipside is that they make reads more complex. When you query Cassandra, it has to merge multiple data files to find the correct results, which can add overhead. This is actually very interested I highly recommend you to look it up online


Data Integrity vs Availability — The Core Trade-Off

This is where it gets interesting and a bit philosophical. The core difference between SQL and NoSQL databases, is Data Integrity versus Availability

SQL databases provide guarantees according to the ACID set of properties: Atomicity, Consistency, Isolation, and Durability. These guarantees mean that your data will always be valid, even in unexpected failures

However, ACID comes with a performance trade-off. For example, an SQL database doesn’t confirm that a write is successful until it’s safely written to disk. This makes sure the data is fully durable, but it can slow down response times, especially under heavy load

On the flip side, NoSQL databases prioritize high availability over strict consistency, using a model called eventual consistency. This means NoSQL databases, like Cassandra or DynamoDB, may return a response to the client without waiting for the data to be fully written to disk or synchronized across all nodes

In simpler terms:


The Cost of Joins, and Why NoSQL Avoids Them

SQL supports joins, powerful, but expensive at scale. They involve reading multiple tables and doing merge joins in memory or on disk. That means more I/O, more CPU, and of course, more latency

NoSQL avoids joins by design. You embed related data in one document (like in MongoDB), or you denormalize the schema, duplicating data. That speeds up reads (because it’s just one fetch) but introduces the risk of data duplication and inconsistency.

Tradeoffs?

Scaling

NoSQL databases like Cassandra or DynamoDB are built to be distributed from day one. SQL has traditionally struggled with horizontal scaling, but now with distributed SQL solutions like CockroachDB, it is catching up

But horizontal scaling in SQL still comes with more pain than in native NoSQL systems


Real-Life Choices

Let’s bring it home.


Conclusion: It’s Not a Battle, it’s a Toolbox

SQL and NoSQL aren't enemies. They're tools. One's a scalpel, one's a chainsaw. You don’t use a scalpel to cut down a tree, and you don’t carve a turkey with a chainsaw (well, you could... but you shouldn’t).

The low-level differences matter, how data is written to disk, how indexes are structured, how memory and disk interact because those differences are the ones that impact performance, scalability, and developer experience overall

Choose based on your real needs, not the hype. And hey, mix and match if you have to. You’re the architect. Build smart.

Tags:
Back to Home