SQL vs NoSQL Databases
1 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. Examples: PostgreSQL, MySQL.
- Strengths: ACID transactions, powerful joins, strong consistency.
- Weaknesses: rigid schema, harder to scale writes horizontally.
- Use when: data is relational and correctness matters (payments, orders).
Non-relational (NoSQL)
| Type | Shape | Examples | Good for |
|---|---|---|---|
| Key-value | key → value |
Redis, DynamoDB | Caches, sessions |
| Document | JSON documents | MongoDB | Flexible/nested data |
| Wide-column | Dynamic columns | Cassandra | Massive write throughput |
| Graph | Nodes + edges | Neo4j | Social graphs |
- Strengths: flexible schema, horizontal scaling, high write throughput.
- Weaknesses: limited joins/transactions, eventual consistency.
ACID vs BASE
- ACID (SQL): Atomic, Consistent, Isolated, Durable — correctness first.
- BASE (NoSQL): Basically Available, Soft state, Eventual consistency — availability first.
How to decide
- Highly relational with transactions? → SQL.
- Massive write scale or flexible schema? → NoSQL.
- Unsure? → Start with PostgreSQL. It scales further than people think.
Real systems are polyglot: SQL for orders, Redis for sessions, a search engine for full-text, object storage for files.