Skip to content

Latest commit

 

History

History
53 lines (39 loc) · 2.74 KB

File metadata and controls

53 lines (39 loc) · 2.74 KB

SQL vs NoSQL

Relational, document, key-value, or wide-column, chosen by the queries the product actually makes.

How to choose a data store, and how to justify it in an interview. The right answer is always "it depends on the access patterns", so state the patterns first.

Quick comparison

Dimension SQL (relational) NoSQL
Schema Fixed, enforced Flexible or schemaless
Joins and transactions Strong, ACID Limited; often eventual consistency
Scaling Vertical first; sharding is harder Designed to scale horizontally
Best for Complex queries, strong consistency, relationships High write volume, simple lookups, flexible data

NoSQL families

Family Example use
Key-value Sessions, caches, simple lookups
Document Catalogs, user profiles, content
Wide-column Time series, large-scale writes
Graph Social graphs, recommendations

How to choose

The same decision as a tree:

flowchart TD
    A["Start: list the access patterns"] --> B{"Multi-row transactions,<br/>joins, or strong consistency?"}
    B -->|yes| SQL["Lean SQL"]
    B -->|no| C{"Scaling writes horizontally,<br/>simple access, flexible schema?"}
    C -->|yes| NO["Lean NoSQL"]
    C -->|no| SQL
    SQL --> D{"Also carrying high-volume<br/>or shape-shifting data?"}
    NO --> D
    D -->|yes| BOTH["Use both: SQL for the core,<br/>NoSQL for the volume"]
Loading
  1. Describe the access patterns: read vs write ratio, query shapes, consistency needs, scale.
  2. If you need multi-row transactions, complex joins, and strong consistency, lean SQL.
  3. If you need to scale writes horizontally with simple access patterns and flexible schema, lean NoSQL.
  4. Many real systems use both: SQL for the core relational data, NoSQL for high-volume or flexible data.

How to talk about it in an interview

Do not say "I would use NoSQL because it scales". Say "the access pattern is a key lookup by user id at high write volume with no joins, so a wide-column store fits, and I accept eventual consistency here because the data tolerates it". Tie the choice to the requirements.

Go deeper