Databases

SQL vs NoSQL

● Beginner ⏱ 9 min read database

The SQL vs NoSQL question comes up in almost every system design discussion. The honest answer is not “SQL is better” or “NoSQL is better” — it depends on the workload. But there is a clear framework for making the decision, and understanding exactly what you trade away in each direction prevents a lot of architectural regret.

Side-by-Side Comparison

DimensionSQL (Relational)NoSQL
Data modelTables, rows, columns with a fixed schemaDocuments, key-value, wide-column, or graph — schema flexible
Query languageSQL — declarative, expressive, standardizedAPI-specific or limited query DSL
JoinsYes — multi-table joins with optimizer supportGenerally no joins; embed or denormalize
ConsistencyACID transactions by defaultOften eventual; tunable in some systems
Horizontal scalingPossible but complex (sharding, distributed SQL)Built-in; designed for it from the start
Schema changesMigrations required; can lock tables at scaleNo migrations; documents can evolve freely
Write throughputHigh on a single node; limited by primary capacityVery high; writes distributed across nodes
Read flexibilityAd-hoc queries over any columnQueries optimized for designed access patterns
MaturityDecades of tooling, ORMs, drivers, monitoringVaries widely by database
Operational complexityWell-understood; managed services abundantVaries; some (Cassandra) are notoriously complex

Schema and Structure

SQL requires you to define your schema before writing data. Every row in a table has the same columns. Changing the schema requires an ALTER TABLE migration, which on a large table can lock reads and writes for minutes or hours unless you use online DDL tools (pt-online-schema-change, gh-ost) or Postgres 12+’s non-blocking ALTER TABLE ... ADD COLUMN.

NoSQL databases are schema-flexible. A document collection can contain documents with different fields. This flexibility is genuinely useful early in a product’s life when requirements shift weekly. It becomes a liability at maturity when you have no idea what shape documents in a collection actually have, and application code is full of if field exists guards.

💡
Schema Flexibility Is Not Free

Schemaless databases move schema enforcement from the database layer to the application layer. Now every service that reads from the collection must handle every possible document shape. Inconsistent writes — from bugs, partial migrations, or old application versions — create silent data quality problems. Many teams add application-level schema validation (e.g., Mongoose validators for MongoDB, or JSON Schema validation) and end up with something more complex than SQL migrations.

Scalability

This is where NoSQL has its strongest case. Most NoSQL databases were designed specifically for horizontal scale from day one:

SQL databases scale vertically by default. A single primary handles all writes. When the primary hits its capacity ceiling:

Most applications never need to scale beyond a single well-tuned SQL primary with a few read replicas. The scale threshold where NoSQL’s horizontal-first design pays off is much higher than engineers typically assume.

Consistency

This is the most consequential trade-off.

SQL gives you ACID transactions. You can transfer money between accounts atomically, decrement inventory and create an order atomically, update multiple tables atomically. All-or-nothing. If the system crashes in the middle, the database rolls back automatically.

Most NoSQL systems are eventually consistent. A write on one node propagates to others asynchronously. Between the write and the propagation, reads may return the old value. This is fine for:

It is not fine for:

Some NoSQL systems bridge this gap. DynamoDB offers strongly consistent reads (at extra cost and latency). MongoDB offers linearizable reads with the right read/write concern. Cassandra can be configured for quorum reads and writes that approach strong consistency. But if you need ACID across multiple entities, SQL is still the cleaner choice.

Query Power

SQL’s declarative query language is extraordinarily powerful. You can:

NoSQL query capabilities are limited to what the database specifically supports. MongoDB’s aggregation pipeline is powerful but nothing like SQL’s full expressiveness. Cassandra only supports queries by partition key and clustering key — no secondary indexes at scale, no ad-hoc queries. Key-value stores support only GET by key. If your query requirements evolve beyond your NoSQL schema’s design, you are in trouble.

When to Choose SQL

When to Choose NoSQL

Using Both Together

The most scalable production systems typically use SQL as the primary data store and specific NoSQL databases layered on top for targeted performance requirements:

In System Design Interviews

When asked SQL vs NoSQL, demonstrate nuance: explain the specific trade-offs, pick one based on the system’s stated requirements, and acknowledge what you give up. A strong answer for a social feed system might be: “I’d use PostgreSQL for user accounts and relationships where strong consistency matters, and Cassandra for the activity feed table because feed writes are extremely high-volume and the read pattern (get feed for user X, sorted by time) maps perfectly to Cassandra’s partition + clustering key model.” This is far more credible than “I’d use MongoDB because it’s flexible.”