CONCEPT SHEET · Concepts

SQL vs NoSQL

One-liner: Relational for structured data with joins and transactions; pick a NoSQL family only when a specific access pattern or scale need justifies it.

ArticleConcepts© Arthur Bernier Jr767 words2 code blocks

Say this#

How it works#

TEXT
Postgres (system of record) --CDC/Debezium--> Kafka --> Elasticsearch (search)                                                    --> Redis (cache/counters)                                                    --> ClickHouse / warehouse (analytics)

Decision flow:

  1. Default: Postgres. Normalized schema, indexes, JSONB for the flexible bits.
  2. Need sub-ms reads or counters/leaderboards/sessions → Redis.
  3. Need write ingest of 100k+/s with simple key access, or multi-region active-active → Cassandra/DynamoDB.
  4. Need full-text or faceted search → Elasticsearch fed by CDC.
  5. Need many-hop relationship queries (friends-of-friends, fraud rings) → graph DB.
  6. Need metrics/events with time-range queries → time-series or columnar.
  7. Need SQL and horizontal writes → distributed SQL (Spanner/CockroachDB), accepting latency cost.

Trade-offs#

ChoiceProCon
RelationalJoins, constraints, transactions, mature tooling, flexible queriesVertical write ceiling; sharding is manual
Key-valueFastest, simplest, trivial to shardNo queries beyond key; no relationships
DocumentNatural for aggregates, flexible schemaJoins weak; duplicated data drifts; big docs cost
Wide-columnLinear write scale, tunable consistency, multi-DCQuery only by designed keys; no ad-hoc queries or joins
GraphTraversals in ms that would be N joinsScale-out is hard; niche
Search engineRelevance, fuzzy, facetsNot a source of truth; near-real-time (refresh ~1 s)
Distributed SQLSQL + scale + strong consistencyHigher write latency; cost; fewer extensions

Numbers#

  • Single Postgres/MySQL primary: order of thousands to low tens of thousands of writes/s; tens of thousands+ reads/s with indexes; comfortable to a few TB.
  • Redis: ~100k ops/s per node; sub-ms latency; memory-bound.
  • Cassandra: ~10k+ writes/s per node and scales linearly with nodes; single-digit ms p99.
  • DynamoDB: item max 400 KB; partition throughput 3,000 RCU / 1,000 WCU; effectively unlimited table throughput.
  • MongoDB: document max 16 MB. Elasticsearch: default refresh interval 1 s.

In the interview#

See also