System design concepts · Data That Doesn't Break

SQL vs NoSQL: How to Choose a Database in System Design

Don't choose a database by brand. Choose it by access pattern: what you read, what you write, how often, and what must stay true.

What you'll be able to explain
  • Describe the main database families and their sweet spots
  • Pick a store from access patterns using a decision guide
  • Model data for queries, not for purity
  • Know when to denormalise and what it costs
  • Justify polyglot persistence without overdoing it

The families

Family Data shape Superpower Weak at Examples
Relational (SQL) Tables, rows, joins Transactions, constraints, flexible queries Horizontal write scaling (without effort) PostgreSQL, MySQL
Key-value key → blob Extreme speed and scale for lookups by key Queries by anything else Redis, DynamoDB, Aerospike
Document key → JSON document Flexible schema, whole-object reads Cross-document joins and transactions MongoDB, Couchbase
Wide-column partition key → sorted rows Massive write throughput, time-ordered data Ad-hoc queries, joins Cassandra, ScyllaDB, HBase
Graph Nodes + edges Multi-hop relationship queries Bulk analytics, sharding Neo4j, Neptune
Search Inverted index Full-text search, relevance, facets Being a source of truth Elasticsearch, OpenSearch
Time-series (series, time) → value Compression, downsampling, range queries General workloads Prometheus, TimescaleDB, InfluxDB
Columnar / OLAP Columns of a huge table Analytical scans over billions of rows Point updates, OLTP ClickHouse, BigQuery, Snowflake
NewSQL SQL, distributed SQL + transactions + horizontal scale Latency of consensus, cost Spanner, CockroachDB, TiDB, YugabyteDB

A decision guide

How to decide
  1. Need multi-row transactions, constraints, or ad-hoc queries, at up to a few TB? → PostgreSQL/MySQL. This is the right default far more often than people admit.
  2. Simple get/put by key at huge scale with predictable latency? → Key-value (DynamoDB, Redis for in-memory).
  3. Very high write rate, append-mostly, read by partition + time range? → Wide-column (Cassandra).
  4. Need SQL semantics and writes beyond one machine, multi-region? → NewSQL.
  5. Search by words or relevance? → Search engine, fed from the source of truth.
  6. Analytics over billions of rows? → Columnar warehouse, fed by CDC or ETL.

Model for your queries

In relational design you normalise first and query later. At scale, especially in NoSQL, you list the queries first and shape the data to answer each one with a single, cheap read.

Example: chat messages in Cassandra.

Query: "Get the latest 50 messages in conversation C."

TABLE messages_by_conversation
  PRIMARY KEY ((conversation_id), message_id)   -- partition key, then clustering key
  WITH CLUSTERING ORDER BY (message_id DESC)

All messages for one conversation live in one partition, sorted newest-first. The query is a single sequential read. Using a time-sortable message_id (Unique ID Generation in Distributed Systems) gives ordering for free.

Common trap

Unbounded partitions. A group chat with 5 years of messages in one partition can grow to gigabytes and hurt the whole cluster. Bucket it: PRIMARY KEY ((conversation_id, month), message_id).