Course map

Topic 062 / Core

Choosing SQL vs NoSQL

Chapter 5.2 · NoSQL and Database Selection

What and why

Every data-store choice is a decision, not a default — made once, early, and expensive to reverse once an application is built around it. Choosing SQL vs. NoSQL means checking access pattern, consistency need, and scale against the trade-offs each side makes, not picking the technology that is trending. Builds on: → 61 (NoSQL databases: key-value, document, wide-column, graph).

Diagram

Dimension Leans SQL Leans NoSQL
Queries ad hoc, joins across entities known, key-driven access
Transactions multi-row, cross-entity single-key or none
Schema stable, shared structure variable per record
Scale fits on well-sized replicas needs horizontal write scale now

How it works

  1. Write down the real access patterns first — the queries the application will actually run — before naming a technology.
  2. Check the consistency and transaction need: does correctness depend on multi-row atomicity (→ 69)?
  3. Check the scale need honestly: is a single well-indexed node with read replicas (→ 72) actually insufficient, measured, not assumed?
  4. Check schema stability: does every record share the same shape, or does it vary enough that a rigid schema fights the data?
  5. Default to relational. Pick NoSQL only when one of the checks above clearly points away from it.

Practical example

An order ledger needs multi-row transactions (debit inventory, create order, charge payment must agree) and ad hoc reporting — relational. A session store needs only "get this blob by session id, expire it after a while" — a key-value store fits with no wasted generality.

When to use it

  • Use when: the checklist above gives a clear answer for the workload at hand.
  • Avoid when: the decision is being made from a resume or a trend rather than the access pattern in front of you.
  • Failure scenarios: choosing NoSQL "for scale" at a few hundred writes per second, then hand-building joins and multi-record consistency in application code that the relational database already provided for free.
  • Simpler alternative: start relational; move the specific hot path that needs it to a purpose-built store later, once the pattern and the scale are both proven.

Practice

(decision drill — judge scenarios and defend, 20 min). For five scenarios — an e-commerce product catalog, a user session store, a bank ledger, product-search autocomplete, and a social "who follows whom" graph — choose SQL or a named NoSQL family for each, and defend it in two sentences citing the deciding factor (access pattern, consistency need, or scale). Done when every answer names the deciding factor, not a product name.

Key takeaway

Default to relational; let a checked, named factor — not fashion — move a workload to NoSQL. Done when you can: defend a SQL-vs-NoSQL choice for a new workload in under a minute using the checklist. Used next in → 76 (distributed database fundamentals); Projects 1, 5.

References

None — this topic makes no external claims.

Source directory

Search the guide