"SQL or NoSQL?" is a question about trade-offs: how your data relates, which queries must be fast, how much consistency you need, and how far writes must scale. A good answer starts from the access patterns and picks the store that serves them, and it's fine to use more than one.
Relational databases
PostgreSQL, MySQL and SQL Server store data in tables with a fixed schema, connect them with joins, and wrap changes in ACID transactions: atomic, consistent, isolated and durable. You can ask questions nobody planned for, because SQL can join and filter any columns.
They scale up well (one large server handles a lot) and scale reads with replicas. Scaling writes past one primary means sharding, which the database doesn't do for you, unless you add a layer such as Vitess or Citus or use a distributed SQL database (Spanner, CockroachDB, YugabyteDB).
The NoSQL families
| Family | Data model | Examples | Good at |
|---|---|---|---|
| Key-value | key → opaque value | Redis, DynamoDB, Memcached | Very fast lookups by key, caching, sessions, counters |
| Document | key → JSON-like document | MongoDB, Couchbase, Firestore | Nested objects read and written as a whole |
| Wide-column | partition key → sorted rows of columns | Cassandra, ScyllaDB, Bigtable, HBase | Huge write volume, time-ordered data, multi-region |
| Graph | nodes and edges | Neo4j, Amazon Neptune | Many-hop relationships (friends of friends, fraud rings) |
| Search | inverted index over documents | Elasticsearch, OpenSearch | Full-text search, relevance, faceted filters |
| Time-series | metric + timestamp → value | Prometheus, InfluxDB, TimescaleDB | Metrics, downsampling, retention windows |
They have little in common except not being relational. What most of them share is that they are designed to partition automatically across many machines, in exchange for giving up general joins and, often, multi-row transactions.
The real trade-offs
| Relational | Typical NoSQL (Cassandra, DynamoDB) | |
|---|---|---|
| Schema | Enforced by the database | Enforced by your code (schema-on-read). It still exists. |
| Queries | Any query, with joins | Only the queries the keys were designed for |
| Transactions | Multi-row ACID | Usually single-item or single-partition; limited multi-item |
| Consistency | Strong on the primary | Often tunable: eventual by default, strong at extra cost |
| Write scaling | One primary, unless you shard by hand | Built in: add nodes and data rebalances |
| Modelling | Normalise, then join | Denormalise: one table per query pattern |
Design from access patterns
With a store like DynamoDB or Cassandra, list the queries first, then design keys that answer each one by reading a single partition. A partition key decides which node holds the data, and a sort key orders items inside the partition.
The same data might be written twice, for example messages by conversation and by user, because each query needs its own layout. Denormalising like this moves cost from reads to writes and puts the job of keeping copies in sync on you.
CAP, stated correctly
The CAP theorem says that during a network partition, a distributed store must choose between consistency (every read sees the latest write, or fails) and availability (every request gets an answer, possibly stale). It doesn't mean "pick two of three" in normal operation. PACELC adds the everyday case: else, when there's no partition, you trade latency against consistency. Cassandra and DynamoDB lean towards availability and low latency. Spanner leans towards consistency.
A sensible default
- Start with PostgreSQL unless you have a concrete reason not to. It handles relational data, JSON documents (
jsonb), full-text search and a lot of scale on one machine with replicas. - Reach for wide-column or DynamoDB when writes are huge and the access patterns are simple and known: chat messages, event logs, IoT readings, activity feeds.
- Add Redis for caching, rate-limit counters and leaderboards; Elasticsearch for search; a time-series store for metrics. These sit beside the main database rather than replacing it.
- Choose distributed SQL when you need both relational transactions and horizontal write scaling, and accept the higher latency per write.
In the game: the database is a relational primary that you scale with replicas and shards by hand. The six shards you need in Hypergrowth are roughly what Cassandra or DynamoDB would give you automatically, with the same rule underneath: writes scale only when each one lands on a single partition.
Interview checklist
- List the main queries and the read/write ratio before naming a database.
- Say whether you need multi-row transactions or joins.
- State the consistency each query needs: strong, read-your-writes or eventual.
- For NoSQL, give the partition key and sort key for each access pattern.
- Use more than one store when it helps, and say how they stay in sync.
Level 12: Hypergrowth
Put this into practice against live traffic. Your progress in the game is saved in your browser.
Play level 12Further reading
- Martin Kleppmann, Designing Data-Intensive Applications (O'Reilly). The standard book on replication, partitioning and consistency.
- Site Reliability Engineering, Google's free book on running reliable systems.
- The Amazon Builders' Library: practical articles on timeouts, retries, caching and load shedding.
- The System Design Primer: a broad, community-maintained overview.