🎯Key Takeaways
- 1Start with SQL (PostgreSQL) unless you have a specific reason not to
- 2Key decision factors: data model, access patterns, scale, consistency, and team expertise
- 3NewSQL (CockroachDB, Spanner) bridges the gap between SQL and NoSQL
- 4Polyglot persistence: use the right database for each microservice's specific needs
How to Choose a Database
Database selection is one of the highest-impact decisions in system design. The wrong choice could mean a painful migration in 6-12 months. The right choice could save your team thousands of engineering hours.
The default answer is PostgreSQL. It handles 90% of use cases well. Only reach for a specialized database when PostgreSQL demonstrably can't meet your requirements.
Define Access Patterns
What queries will you run most often? Read-heavy or write-heavy? Point lookups or range scans? Joins needed?
If you need complex joins and transactions → SQL. If you need simple key-value lookups at massive scale → NoSQL.
Database Decision Matrix
| Use Case | Recommended | Why |
|---|---|---|
| General purpose / CRUD | PostgreSQL | ACID, flexible, mature, great default |
| Session storage / caching | Redis | In-memory, sub-ms latency, TTL support |
| Full-text search | Elasticsearch | Inverted index, relevance scoring, aggregations |
| Time-series / IoT | TimescaleDB or InfluxDB | Optimized for time-ordered writes and retention |
| Social graph / relationships | Neo4j | Native graph traversal, Cypher query language |
| High-write event log | Cassandra / ScyllaDB | Write-optimized, linear scalability |
| Global distributed SQL | CockroachDB / Spanner | SQL + horizontal scaling + strong consistency |
| Real-time analytics | ClickHouse / Druid | Columnar, fast aggregations on large datasets |
Advantages
- •Framework prevents analysis paralysis
- •Polyglot persistence optimizes each service
- •Understanding trade-offs prevents costly migrations
Disadvantages
- •More databases = more operational complexity
- •Team must learn multiple technologies
- •Data consistency across databases is your responsibility
🧪 Test Your Understanding
What should be your default database choice if you have no specific requirements?