# SQL vs NoSQL explained

Source: https://systemdesignsim.com/system-design/sql-vs-nosql

System design · Access patterns, transactions and data models

Choose a database from the reads, writes and correctness rules your system must support. Relational databases organise related records into tables; NoSQL covers several models, including documents and key-value stores, with different query and transaction boundaries. The useful interview answer names the operations and explains their cost and failure behaviour, rather than claiming that one category is always faster.

Updated October 28, 2026 · 5 min read

[Calculate: database size](https://systemdesignsim.com/learn/database-sizing)

![SQL vs NoSQL architecture diagram](https://systemdesignsim.com/diagrams/sql-vs-nosql-system-design-diagram.svg)

The order API writes authoritative orders. A change stream builds a separate search view for support, which never decides checkout.

## The short version

* SQL is a query language; NoSQL is an umbrella term. Compare specific databases, not categories.
* Start from invariants and access patterns: key, filter, sort, bound and freshness per read.
* Several NoSQL databases have transactions. Isolation, read consistency and projection freshness are separate questions.
* Pick one authoritative store. Search views and caches are derived, can lag, and must be rebuildable.

## Clarifying questions to ask first

* What must stay correct under concurrent writes? (Assume no double charge and no reservation below available stock.)
* Which reads matter? (Assume order lookup, a customer's recent orders and a support search across customers.)
* What changes together? (Assume an order holds line items and a purchase-price snapshot; the catalogue changes separately.)
* What skew should we expect? (Assume one large customer can dominate traffic.)
* How do we recover from a bad write? (Assume tested restores, and a search view rebuildable from orders.)

## Relational, document and key-value models

Document, key-value and wide-column stores differ in access paths and guarantees, and a product with SQL syntax can distribute data unlike a single-primary deployment. Relational constraints enforce uniqueness, foreign keys and row checks near the data (https\://www\.postgresql.org/docs/current/ddl-constraints.html), but not rules involving an external payment or another service. The table lists questions to investigate, not a feature matrix.

| Decision            | Relational approach                      | Document or key-value approach           |
| ------------------- | ---------------------------------------- | ---------------------------------------- |
| Order detail        | Join related order records               | Read one order aggregate                 |
| Customer history    | Index customer and creation time         | Design a customer-oriented key or index  |
| Changing attributes | Typed columns or JSON                    | Flexible fields with validation          |
| Cross-record rule   | Constraints and isolation                | Conditional writes and transaction scope |
| New support query   | Plan and index it                        | Another index or projection?             |
| Scaling             | Measure contention, replicas, partitions | Measure key skew, indexes, coordination  |

## Access patterns before the database name

Order by ID, a customer's recent orders and support search by payment reference are three access patterns over similar records. A relational design indexes history; a document design embeds the bounded line items; a key-oriented design needs a deliberate history path. AWS's DynamoDB modelling example shows access-pattern-driven grouping (https\://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-modeling-nosql-B.html), not a rule to put everything in one table.

If the support field isn't a key, the query scans, needs another index or reads a search projection. Precomputing every view adds writes and repair work.

## Transactions, isolation and read consistency

A transaction groups changes; isolation defines what concurrent operations see (https\://www\.postgresql.org/docs/current/transaction-iso.html). Neither says whether a replica caught up. For two checkouts racing for the last item, state the invariant, pick a database-enforced condition, lock or transaction, and say what the loser gets and how a retry avoids a second charge. The payment never joins the order transaction ([distributed transactions](https://systemdesignsim.com/system-design/distributed-transactions)).

MongoDB documents multi-document ACID transactions shaped by read and write concerns (https\://www\.mongodb.com/docs/manual/core/transactions/). DynamoDB documents transaction APIs distinct from batches, and read consistency that differs for global secondary indexes (https\://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html). Check the real post-checkout read path before promising read-your-writes.

## Schema and changing data

A schema is a contract for meaning. Varied document fields still need validation and rules for old records, and embedding suits bounded aggregates, not growing histories (https\://www\.mongodb.com/docs/manual/data-modeling/). A purchase-price snapshot is deliberate duplication; for every copy, name the owner and the repair rule. PostgreSQL's jsonb (https\://www\.postgresql.org/docs/current/datatype-json.html) lets a validated payload sit beside typed columns. Any schema change needs old and new readers, a safe backfill and defined nulls and defaults.

## Indexes, partition keys and capacity

Every index or duplicated view adds work per write ([database indexing](https://systemdesignsim.com/system-design/database-indexing)). As a teaching estimate, 200 records a second at 2,000 bytes is 400,000 bytes a second, or 34.56 GB a day, before indexes, replicas and retention. Peak traffic and a large customer need their own estimates.

A partition key must spread busy operations, not just IDs (https\://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-partition-key-design.html); one popular item stays hot. Neither model removes finite CPU, I/O or coordination ([database sharding](https://systemdesignsim.com/system-design/database-sharding)).

## Projections, migration and recovery

Projection consumers lag, see duplicates and restart mid-backfill, so give changes stable IDs or versions and keep enough history to rebuild. A migration needs read comparisons, invariant checks, reconciliation and a rollback route. A replica repeats a bad write, so test restores (https\://www\.postgresql.org/docs/current/backup.html). The simulator doesn't execute SQL, document queries or transactions.

## Where it's used

* [UPI payments](https://systemdesignsim.com/system-design/upi-payments) separates an authoritative transaction from retries and external outcomes.
* A [key-value store](https://systemdesignsim.com/system-design/key-value-store) makes key identity explicit; compare it with this guide's changing support query.
* [Database sharding](https://systemdesignsim.com/system-design/database-sharding) applies when the limit is partition ownership or a hot key.
* The [database sizing calculator](https://systemdesignsim.com/learn/database-sizing) ties proposed reads to memory, writes and retained data.

## Common traps

* Choosing NoSQL because traffic is high without naming a key. Show the busiest partition's reads and writes.
* Treating JSON as a model with no contract. Validate meaning and test older records.
* Replacing a transaction with a batch call. Check atomicity and failure reporting for that exact API.
* Making a search index the authority for a new checkout.
* Counting raw records as the whole bill. Add indexes, replicas, retained history and recovery work.

## Follow-up questions interviewers ask

* "Which would you choose first?" The simplest database that supports the invariants and queries; often a familiar relational one.
* "Can a document database store relationships?" Yes, by embedding or references. Ask what changes together, how big the aggregate grows and what consistency the read needs.
* "When would you change it?" On measured contention, a badly served query or a new correctness requirement.

## Frequently asked questions

### What is the difference between SQL and NoSQL?+

SQL is a query language commonly associated with relational databases. NoSQL groups several other models, such as document and key-value stores, with no uniform set of guarantees.

### Is NoSQL always faster than SQL?+

No. Query shape, indexes, item size, partition skew and correctness requirements decide the work. Benchmark representative operations under the guarantees you need.

### Can NoSQL databases support ACID transactions?+

Some do, including MongoDB and DynamoDB through documented transaction APIs. Check their scope and read behaviour for your configuration. A batch is not automatically atomic.

### Can one system use both relational and NoSQL stores?+

Yes, if each store has a clear purpose and the authoritative copy is explicit. Derived views need defined freshness, replay and reconciliation, and every extra store adds failure modes.

## More system design guides

[All 76 guides](https://systemdesignsim.com/system-design)

* [Distributed Transactions explained2PC, sagas, outbox, idempotent consumers](https://systemdesignsim.com/system-design/distributed-transactions)
* [Design a UPI Payment App like PhonePe or Google PayIdempotency, pending payments, no double debits](https://systemdesignsim.com/system-design/upi-payments)
* [Database Sharding explainedShard keys, hot partitions, resharding](https://systemdesignsim.com/system-design/database-sharding)
* [Design a Key-Value StorePartitioning, replication, quorums](https://systemdesignsim.com/system-design/key-value-store)
* [Design a Chat SystemQueues, write scaling, delivery lag](https://systemdesignsim.com/system-design/chat-system)
* [Leader Election and Consensus explainedRaft, quorums, leases, split brain](https://systemdesignsim.com/system-design/leader-election)

## Now fix it yourself.

Run the design under real traffic and see what breaks first. No signup.

[Calculate: database size](https://systemdesignsim.com/learn/database-sizing)
