A SQL database stores data in tables with a fixed structure and lets us query it with SQL. A NoSQL database is basically everything else — anything that doesn’t use the classic table-and-rows model.
In simple language — SQL is a spreadsheet with strict columns; NoSQL is a big flexible bag where each item can look a little different.
This is one of the most common system-design warmups. Interviewers don’t want a religious war — they want to hear us pick the right tool for a workload and explain the trade-off.
The relational (SQL) model
SQL databases — Postgres, MySQL, SQL Server — store data in tables (rows and columns). A few core ideas:
- Schema — we define the columns and their types up front. Every row must fit.
- Joins — we split data across tables and stitch them back together at query time. One
userstable, oneorderstable, joined onuser_id. No duplication. - ACID — transactions are atomic, consistent, isolated, durable. In plain words: money doesn’t vanish mid-transfer. (We cover ACID in depth in its own note.)
The big win is data integrity. The schema and foreign keys stop us from writing garbage. If a query needs data from five tables, SQL is genuinely great at it.
-- one order, but user + product data pulled in via joins
SELECT u.name, p.title, o.quantity
FROM orders o
JOIN users u ON u.id = o.user_id
JOIN products p ON p.id = o.product_id
WHERE o.id = 42;
The NoSQL families
“NoSQL” is an umbrella, not one thing. There are four families, and knowing which is which is the interview gold.
MongoDB, Couchbase.
Catalogs, user profiles.
Redis, DynamoDB.
Caches, sessions.
Cassandra, HBase.
Time-series, event logs.
Neo4j.
Social graphs, fraud.
The document family is the one people usually mean by “NoSQL”. Instead of joining tables, we store the whole thing as one document — user plus their orders nested inside.
// a document — everything about the order in one place, no joins
{
_id: 42,
user: { name: "Asha", email: "asha@x.com" },
items: [{ title: "Keyboard", qty: 1 }],
total: 4999
}
Schema-on-write vs schema-on-read
This is the real philosophical difference, and a great line to drop in an interview.
- Schema-on-write (SQL) — the database checks our data against the schema when we write it. Bad shape? Rejected. Structure is guaranteed on the way in.
- Schema-on-read (NoSQL) — we write whatever we want, and the reading code figures out the shape. Flexible, but now the burden of “is this field even here?” lives in our application.
Think of it like — SQL is a bouncer checking IDs at the door; NoSQL lets everyone in and sorts it out at the bar.
Scaling differences
- SQL scales vertically — mostly a bigger box (more CPU, RAM). Horizontal scaling (sharding across machines) is possible but painful, because joins and transactions across nodes are hard.
- NoSQL scales horizontally — built from day one to spread data across many cheap machines. That’s often the whole point. The catch: to get that, most NoSQL stores relax consistency (eventual consistency — reads might briefly see stale data).
When to use which
- Reach for SQL when data is relational, integrity matters, and we run complex queries — payments, orders, anything financial. Default here unless we have a reason not to.
- Reach for NoSQL when the shape is fluid, we need massive write throughput or horizontal scale, or the access pattern is dead simple (key → value) — caches, event firehoses, flexible catalogs.
Honestly, most systems end up using both: Postgres for the source of truth, Redis for caching, maybe Elasticsearch for search.
Interview soundbite
SQL = tables, fixed schema, joins, ACID, schema-on-write, scales up. NoSQL = flexible model in four flavors (document, key-value, wide-column, graph), schema-on-read, scales out with eventual consistency. Default to SQL for relational data with integrity needs; pick NoSQL for scale, flexibility, or simple key-based access — and most real systems mix both.