"Which database would you use?" is the most common trade-off question in a system design interview, and the worst answer is a brand name. The real question is what your data looks like, how it is read and written, and what must never be wrong. This lesson gives you a way to choose between a relational (SQL) database and a NoSQL store, a rule you can say out loud, and the hybrid answer most real systems end up with.
Detailed Notes
What Problem Are We Solving?
Every system must keep data somewhere. Two families of databases dominate the answer, and they optimise for different things.
A relational database (SQL database, for example PostgreSQL or MySQL) stores data in tables with a fixed set of columns. Tables are linked by keys, and you can join them (combine rows from several tables in one query). It gives you ACID transactions: a group of changes either all happen or none do.
A NoSQL database is a family of stores (key-value, document, wide-column, graph, as covered in the NoSQL families lesson) that usually give up joins and some transaction guarantees in exchange for easier horizontal scaling (adding more machines) and a flexible data shape.
The choice matters because it is expensive to reverse. Moving 10 TB from one engine to another means a data migration, a dual-write period and a rewritten data access layer.
Two numbers show why the answer depends on the workload.
text
Orders for a shop: 50M orders per year x 1 KB = 50 GB per year
Peak 200 writes per second -> one SQL server is fine
Activity events: 100,000 events/s x 1 KB = 100 MB/s
100 MB/s x 100,000 s per day = 10 TB per day
-> no single machine can hold or write this
The order data is small, relational and must be correct, so SQL is comfortable. The activity stream is huge, append-heavy and has no joins, so it needs a store built to spread writes over many machines.
SQL vs NoSQL at a GlanceComparison
SQL
tables, joins, ACID
1
Design normalised tables
orders, customers, items
2
Write inside a transaction
all or nothing
3
Query with joins
any column, any combination
4
Scale reads with replicas
writes still go to one leader
Ad hoc queries and reports
Transactions and constraints
One copy of each fact
Write scale-out needs sharding
Joins break across shards
Best for correctness and flexibility
NoSQL
key lookups, scale-out
1
Design around the query
one document per order
2
Write to the partition
hash(key) picks the node
3
Read by key
single-partition lookup
4
Add nodes for capacity
reads and writes both scale
Writes scale with nodes
Flat latency by key
Flexible shape
Queries must be known
Duplicated data to keep in sync
Best for volume and simple access
Key point. SQL optimises for questions you have not asked yet. NoSQL optimises for the question you ask a billion times.
The same order system, stored two ways.
Option 1: SQL (relational)
How it works
You design tables up front (a schema): an orders table, a customers table, an order_items table. Each row has a primary key, and other tables refer to it with a foreign key. A query states what you want, and the database decides how to get it:
text
SELECT c.name, SUM(i.price * i.qty)
FROM orders o
JOIN customers c ON c.id = o.customer_id
JOIN order_items i ON i.order_id = o.id
WHERE o.created_at > '2026-01-01'
GROUP BY c.name;
Because the data is normalised (each fact stored once), a customer's address changes in one row. Secondary indexes (extra lookup structures, see the indexing lesson) let you query by almost any column. A transaction can move money between two accounts and guarantee that both updates happen or neither does.
Pros
Flexible queries. You can ask questions you did not plan for. New reports and filters rarely need a redesign.
Strong guarantees. ACID transactions and constraints (unique, foreign key, not null) push correctness into the database instead of every service.
Mature tooling. Backups, replication, monitoring and decades of operational knowledge.
One copy of each fact. Normalisation avoids contradicting duplicates.
Cons
Scaling writes is hard. A single leader takes all writes. You can add read replicas easily, but spreading writes needs sharding (splitting rows across machines), and then joins and transactions across shards become slow or impossible.
Rigid schema. Changing a column on a 2 TB table needs careful migration.
Cost of joins at scale. A join over billions of rows spread across shards is where relational designs strain.
When to use it
Choose SQL when the data is relational, correctness matters more than raw write throughput, and one primary can handle the load, which means roughly up to a few thousand writes per second and a few terabytes. Typical fits: orders, payments, inventory, bookings, user accounts.
Realistic scenario. A ticket-booking service must never sell the same seat twice. Two buyers click the same seat at the same moment. In SQL you run one transaction: UPDATE seats SET status='held' WHERE id=42 AND status='free'. Exactly one of the two updates affects a row, the other sees zero rows and gets "seat taken". The database enforced the rule. In a store without transactions you would have to build that guarantee yourself.
Option 2: NoSQL
How it works
You pick the NoSQL family that matches your access pattern and design the data around the queries you will run, not around the entities. In a document store you might embed everything about an order in one document:
One read returns the whole order, with no join. A key-value or wide-column store goes further: data is partitioned by a key (the partitioning lesson), so each key lives on one machine and new machines add capacity. The store is usually eventually consistent by default (replicas may briefly disagree, covered in the consistency lesson) and often offers transactions only within a single item or partition.
Pros
Horizontal scale built in. Add nodes to add write capacity. 100,000 writes per second is a normal day for a wide-column cluster.
Predictable latency. A key lookup touches one partition, so latency stays flat as data grows.
Flexible schema. Different documents can have different fields, which suits fast-changing products.
Shape fits the query. Storing data the way you read it makes the common read a single lookup.
Cons
You must know the queries up front. Asking a new question may mean a new table, a new index or a full scan.
Duplicated data. Denormalising (copying data into several places) means an update must change every copy, and a bug can leave them inconsistent.
Weaker guarantees. Multi-item transactions and joins are limited or missing, so the application takes on more correctness work.
Less uniform tooling. Each store has its own query model and failure behaviour.
When to use it
Choose NoSQL when the access pattern is simple and known (mostly lookups by key), the volume or write rate exceeds one primary, or the data shape varies. Typical fits: activity feeds, sessions, shopping carts, IoT readings, chat messages, product catalogs with varied attributes.
Realistic scenario. A chat app stores 5 billion messages. The only read is "latest 50 messages in conversation X". A wide-column store with partition key conversation_id and clustering key timestamp answers that from one partition in a few milliseconds and spreads conversations evenly across the cluster. There are no joins to lose, because nobody asks for one.
The hybrid: polyglot persistence
Most real systems use both. Polyglot persistence means each service picks the database that fits its data. Payments and orders stay in SQL for transactions. The product catalog goes to a document store, the search box to a search index, sessions to a key-value cache. Changes in the source of truth are copied to the other stores through a queue or change stream, so each read-optimised copy can be rebuilt.
The cost is operational: more systems to run, and copies that are slightly behind. State that cost in the interview.
Polyglot Persistence for a ShopArchitecture
Key point. Pick the store per access pattern, and keep exactly one source of truth.
Each store holds what it is good at. The order database is the source of truth; the others are rebuildable copies.
Interview Discussion
A strong answer follows four steps and keeps it short.
Name the access pattern. "Reads are by order id and by customer, writes are about 200 per second."
Name the correctness need. "Payments must not be lost or double charged."
Do the number. "50 GB per year fits on one primary with replicas."
Decide, then say what would change your mind. "I'd start with PostgreSQL. If writes grew past what one primary handles, I'd shard by customer id or move the event stream to a wide-column store."
Interview tip. Never say "NoSQL because it scales". PostgreSQL scales to a large size with replicas and partitioning, and many NoSQL stores scale poorly for the queries you actually need. Tie the choice to a specific access pattern.
Interview discussion. "I'd model orders in SQL because they are relational and need transactions. The click stream is append-only, 10 TB a day, queried by key and time, so I'd put that in a wide-column store. A change stream feeds the search index."
Trade-off thinking. SQL buys flexibility and correctness and pays with scale-out difficulty. NoSQL buys scale and predictable latency and pays with query flexibility and application-level correctness. Start with the simplest store that meets today's numbers, and say where the design would split.
Two common traps: choosing NoSQL "to be safe for scale" when the data is 50 GB (you give up joins for nothing), and choosing SQL for a firehose without mentioning sharding.
Final Takeaway
Choose SQL when data is relational, transactions matter and one primary can carry the writes. Choose NoSQL when the access pattern is simple and known, and volume or write rate needs scale-out. Use both when parts of the system differ, and keep one source of truth that feeds the others. The best interview answer is a decision rule backed by a number, not a product name.