Home/Learn/System Design/SQL vs NoSQL
system designbeginner

SQL vs NoSQL: How to Choose

Every system design answer faces the same fork: SQL or NoSQL. The correct choice depends on consistency needs, write scale, and query patterns, and interviewers listen for a reasoned decision rather than a default. This guide gives you the decision framework with real product examples.

1. The Two Families

SQL (Relational)

Rows in tables, fixed schema, ACID transactions, joins, and secondary indexes. PostgreSQL and MySQL are the standards. Shines when data is highly relational and correctness matters.

NoSQL (Four Subtypes)

  • Key-value: Redis, DynamoDB. O(1) lookups by key; great for sessions and caches.
  • Document: MongoDB. JSON documents, flexible schema; great for catalogs and profiles.
  • Wide-column: Cassandra, Bigtable. Sparse columns at huge scale; great for time series and events.
  • Graph: Neo4j. Node-edge queries; great for social graphs and fraud detection.

2. Decision Criteria (the Interview Cheat Sheet)

Ask these five questions in order:

  1. Need ACID transactions? Money movement, inventory, booking : SQL.
  2. Need joins / ad-hoc analytics? Reports, relationships : SQL.
  3. Massive write scale (millions/sec)? Events, logs, telemetry : NoSQL (Cassandra).
  4. Schema changing fast or unknown? Product catalog, ML features : NoSQL (MongoDB).
  5. Access mostly by key? Sessions, URL mapping : NoSQL (Redis/DynamoDB).
graph TD
    Q1{"ACID / joins
critical?"} -->|"Yes"| SQL["PostgreSQL / MySQL"]
    Q1 -->|"No"| Q2{"Huge write scale?"}
    Q2 -->|"Yes"| W["Cassandra"]
    Q2 -->|"No"| Q3{"Flexible schema?"}
    Q3 -->|"Yes"| D["MongoDB / DynamoDB"]
    Q3 -->|"No"| K["Redis key-value"]
    style Q1 fill:#D97A2B,stroke:#B86418,color:#fff

3. The Sharding Reality Check

The deep reason NoSQL wins at scale is that relational models break under sharding: joins become cross-node queries, secondary indexes need scatter-gather, and transactions across shards get painful. NoSQL gives up those features up front to scale horizontally cleanly.

Modern SQL handles it too (Citus, Vitess, CockroachDB), but with real complexity. If the interviewer pushes on scale, that is the discussion they want.

4. Real Product Examples

  • Chat: message history is append-only and read by key (chatId + timestamp) : Cassandra or DynamoDB.
  • News feed: fan-out writes at huge scale, ordered reads : Redis for hot feed, Cassandra for archive.
  • E-commerce orders: strict inventory and payments : PostgreSQL with transactions.
  • Product catalog: many attributes, sparse fields : MongoDB documents.
  • Search: inverted index : Elasticsearch (its own category, not classic SQL/NoSQL).

5. Consistency Trade-offs

SQL defaults to strong consistency; most NoSQL defaults to eventual. This maps directly to the CAP theorem: choose CP when stale reads are unacceptable, AP when availability beats freshness. State which side your pick lands on and why.

6. Polyglot Persistence

Best-of-breed systems are rarely one store. A video platform keeps subscriptions in PostgreSQL, watch-history in Cassandra, hot sessions in Redis, and search in Elasticsearch. Naming a two-or-three-store design is a senior signal : one database for everything is a junior red flag.

7. Common Interview Mistakes

  • Defaulting to NoSQL "because it scales" without naming the trade-offs.
  • Claiming SQL cannot scale : post-sharded SQL and Vitess/cockroachDB are valid answers.
  • Ignoring the difference between NoSQL subtypes.
  • Picking a store that forces cross-database consistency for money flows.
  • Not mapping the choice to the CAP trade-off.

8. Summary: Key Decisions

Walk the criteria tree, justify the pick with the workload, name the consistency trade-off, and offer a polyglot option if the system has distinct access patterns. That sequence answers 90% of SQL-vs-NoSQL probes.

Frequently Asked Questions

Is MongoDB better than PostgreSQL for a new app?

For a new app with a mostly-relational schema, PostgreSQL is usually the safer default because it is flexible enough (JSONB) to cover document needs while keeping SQL and transactions. Reach for MongoDB only when the document shape is genuinely variable or write scale demands it.

Why is DynamoDB so common in system design answers?

DynamoDB is the flagship of the key-value family: single-digit-millisecond reads by partition key, auto-sharding, and enormous write scale. Candidates name it as the "scale, simple access pattern" default, which pairs naturally with Redis for hot data.

Can SQL and NoSQL be combined for a feed feature?

Yes, and it is a classic pattern: the canonical post data lives in the relational store, while the fan-out feed index lives in Redis for fast timeline reads. This keeps transactional integrity for content while making reads scale.

Related Tutorials

Put it into practice

Ready to practice?

Practice this design in a live system design mock interview with InterviewSkool's AI interviewer.

Start a System Design Interview →