SQL vs NoSQL Databases
2 min read
Choosing a Database
The database is usually the hardest part to change later, so choose deliberately.
Relational (SQL)
Data in tables with a fixed schema and relationships. Examples: PostgreSQL, MySQL.
- Strengths: ACID transactions, powerful joins/queries, strong consistency, mature tooling.
- Weaknesses: rigid schema, harder to scale writes horizontally.
- Use when: data is structured and relational, correctness matters (payments, orders, users).
Non-relational (NoSQL)
A family of models rather than one thing:
| Type | Shape | Examples | Good for |
|---|---|---|---|
| Key-value | key → value |
Redis, DynamoDB | Caches, sessions |
| Document | JSON documents | MongoDB | Flexible/nested data |
| Wide-column | Rows with dynamic columns | Cassandra | Massive write throughput |
| Graph | Nodes + edges | Neo4j | Social graphs, recommendations |
- Strengths: flexible schema, horizontal scaling, high write throughput.
- Weaknesses: limited joins/transactions, eventual consistency, you design around access patterns.
ACID vs BASE
- ACID (SQL): Atomic, Consistent, Isolated, Durable — correctness first.
- BASE (many NoSQL): Basically Available, Soft state, Eventual consistency — availability first.
How to decide
- Is the data highly relational with transactions? → SQL.
- Do you need massive write scale or flexible schema? → NoSQL.
- Unsure? → Start with PostgreSQL. It scales further than people think and gives you JSON columns for flexibility.
Real systems are polyglot: SQL for orders, Redis for sessions, a search engine for full-text, an object store for files.