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.
| 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 |
| 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 |
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"]
- Describe the access patterns: read vs write ratio, query shapes, consistency needs, scale.
- If you need multi-row transactions, complex joins, and strong consistency, lean SQL.
- If you need to scale writes horizontally with simple access patterns and flexible schema, lean NoSQL.
- Many real systems use both: SQL for the core relational data, NoSQL for high-volume or flexible data.
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.
- The concrete versions of this decision: PostgreSQL vs DynamoDB vs Cassandra and DynamoDB vs MongoDB
- Data storage lessons in the course