Beginner → Intermediate15 min read· Topic 2.6

Database selection framework

SQL vs NoSQL decision matrix, NewSQL, polyglot persistence

🎯Key Takeaways

  • 1
    Start with SQL (PostgreSQL) unless you have a specific reason not to
  • 2
    Key decision factors: data model, access patterns, scale, consistency, and team expertise
  • 3
    NewSQL (CockroachDB, Spanner) bridges the gap between SQL and NoSQL
  • 4
    Polyglot 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 CaseRecommendedWhy
General purpose / CRUDPostgreSQLACID, flexible, mature, great default
Session storage / cachingRedisIn-memory, sub-ms latency, TTL support
Full-text searchElasticsearchInverted index, relevance scoring, aggregations
Time-series / IoTTimescaleDB or InfluxDBOptimized for time-ordered writes and retention
Social graph / relationshipsNeo4jNative graph traversal, Cypher query language
High-write event logCassandra / ScyllaDBWrite-optimized, linear scalability
Global distributed SQLCockroachDB / SpannerSQL + horizontal scaling + strong consistency
Real-time analyticsClickHouse / DruidColumnar, 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

Knowledge Check1/1

What should be your default database choice if you have no specific requirements?