SQL vs NoSQL
"SQL or NoSQL?" is one of the first architectural decisions for a data-driven app — and one of the most over-debated. The honest answer is it depends on your data and access patterns, not on which is "modern." This page contrasts the relational and document models concretely, dispels the common myths, and gives a practical framework for choosing — including the increasingly common answer of "both."
The core difference: structure
SQL (relational) — data split across tables, joined by keys:
users orders
┌────┬───────┐ ┌────┬─────────┬────────┐
│ id │ name │ │ id │ user_id │ total │
├────┼───────┤ ├────┼─────────┼────────┤
│ 1 │ Ada │◀──────│ 9 │ 1 │ 49.99 │
└────┴───────┘ └────┴─────────┴────────┘
NoSQL (document) — related data nested in one document:
{
"_id": 1, "name": "Ada",
"orders": [ { "id": 9, "total": 49.99 } ] // embedded
}Side by side
SQL (relational) | NoSQL (document) | |
|---|---|---|
Schema | Fixed, enforced by the DB | Flexible, per-document |
Relationships | Joins across tables | Embed or reference manually |
Query language | SQL (standardized) | DB-specific (e.g. Mongo query API) |
Transactions | Strong, multi-row ACID | Improving; best within a document |
Scaling | Vertical; harder to shard | Horizontal sharding built-in |
Best fit | Structured, related data | Flexible, denormalized, high write volume |
ACID vs BASE
ACID (typical SQL) | BASE (typical NoSQL) |
|---|---|
Atomicity — all-or-nothing | Basically Available |
Consistency — valid states only | Soft state |
Isolation — concurrent safety | Eventually consistent |
Durability — survives crashes | (favors availability over immediate consistency) |
Myths worth dropping
"NoSQL is faster." — Only for certain access patterns. SQL with proper indexes is extremely fast; the wrong NoSQL schema is slow.
"NoSQL is schemaless, so no design needed." — You still design a schema; you just enforce it in your app instead of the DB. Undisciplined documents become a mess.
"SQL can't scale." — Postgres runs enormous workloads; read replicas and partitioning go a long way before sharding is needed.
"Joins are bad." — Joins are a feature. Avoiding them by duplicating data shifts the cost to write-time consistency.
A practical decision framework
Lean SQL when… | Lean NoSQL when… |
|---|---|
Data is highly relational (users↔orders↔items) | Data is self-contained documents |
You need multi-record transactions (payments) | Schema changes constantly / varies per record |
Complex ad-hoc queries & reporting | Massive write throughput / horizontal scale |
Strong consistency is required | Eventual consistency is acceptable |
You want a standard, portable query language | Documents map naturally to your objects |
The common real-world answer: both (polyglot persistence)
Postgres → core transactional data (users, orders, payments) MongoDB → flexible documents (CMS content, event logs) Redis → cache + sessions + rate-limit counters Elastic → full-text search