SQL vs. NoSQL: Choosing the Right Database
The choice rarely determines whether a feature is possible — it determines how much friction the team fights for the system's whole lifetime.
Beginner
orders table, every order has exactly a customer ID, a restaurant ID, a total, and a status; that regularity is exactly what a relational schema is good at enforcing.| Family | Data shape | Good fit | Example |
|---|---|---|---|
| Key-value | An opaque value behind a unique key | Session data, shopping carts, caches | Redis, DynamoDB |
| Document | Semi-structured documents (JSON-like), fields can vary per record | Product catalogs where different item types have different attributes | MongoDB, Couchbase |
| Columnar | Data stored by column instead of by row, optimized for scanning one attribute across many rows | Analytics, time-ordered event data at huge scale | Cassandra, HBase |
| Graph | Nodes and edges representing entities and their relationships | Social graphs, recommendation engines | Neo4j |
{ "itemId": "pz_104", "type": "pizza", "size": "large", "toppings": ["mushroom","olive"] }
{ "itemId": "cf_29", "type": "coffee", "size": "medium", "milk": "oat" }
| If the data is… | …lean toward |
|---|---|
| Structured, and correctness of multi-step writes matters (payments, inventory) | Relational (SQL) |
| Simple key-to-blob lookups at very high throughput | Key-value store |
| Irregular shape across records, but queried mostly by ID | Document store |
| Enormous volume, a handful of known query patterns, append-heavy | Columnar store |
| Fundamentally about relationships between entities | Graph database |