Loading…
Loading…
Charting your lesson…
Opening your lesson…
Databases — SQL vs NoSQL
Lesson 4 of 4
6 steps•about 11 min•11 flashcards
Step 1/ 61 min
"Would you use SQL or NoSQL here?" comes up in almost every system-design interview, and the wrong instinct is to pick a favourite. The right instinct is to choose based on the data and access patterns, and to justify it. Candidates who can articulate when each shines — and admit that many real systems use both — stand out immediately.
What this covers / why it matters: the difference between relational (SQL) and non-relational (NoSQL) databases, when to use each, and how to justify the choice in a design. It's a near-certain question with a clear right way to answer.
Step 2/ 61 min
| Prefer SQL when | Prefer NoSQL when |
|---|---|
| Data is structured with clear relationships | Schema is flexible or evolving |
| You need multi-row transactions / strong consistency (payments, orders) | You need massive scale and high write throughput |
| Complex queries and joins matter (reporting) | Access is simple key-based lookups |
| Data volume is moderate | Data is huge and must shard across many nodes |
Mature systems use both — "polyglot persistence": e.g. PostgreSQL for orders and payments (needs transactions), Cassandra for a high-volume activity feed, Redis for sessions/cache, Elasticsearch for search. The strong interview move is to tie the choice to consistency needs and access patterns: "This data needs transactional integrity, so relational; that data is huge and write-heavy with simple lookups, so a wide-column NoSQL store." Also connect it to CAP: NoSQL stores often lean AP (availability + partition tolerance) with eventual consistency, while relational systems lean CP.
Step 3/ 61 min
"Design the data storage for an e-commerce site."
"I'd use different stores for different needs rather than forcing one. Orders, payments and inventory go in a relational database like PostgreSQL — these need ACID transactions (you can't half-charge a customer) and involve relationships and reporting queries with joins. The product catalog could stay relational too, or move to a document store like MongoDB if product attributes vary a lot by category, since a flexible schema fits that well. User sessions and the cart go in Redis (a key-value store) for fast, ephemeral access. A high-volume activity feed or clickstream — huge write throughput, simple access, tolerant of eventual consistency — fits a wide-column store like Cassandra. And product search goes to Elasticsearch. So the answer isn't SQL or NoSQL; it's SQL where I need transactions and relationships, NoSQL where I need scale and flexibility, chosen per data type."
Justified per-component choices tied to consistency and access patterns — exactly the reasoning interviewers want.
Step 4/ 61 min
Step 5/ 61 min
Picking SQL or NoSQL as a blanket "better" choice. The correct answer is always conditional on the data and access pattern. In particular, never put transactional data like payments or orders in an eventually-consistent NoSQL store just because it "scales" — consistency requirements come first.
Step 6/ 6· Worked examples1 min
Problem/Question: "For a new social app, would you pick a SQL or a NoSQL database? Justify."
Solution/Model answer:
SQL (relational, e.g., PostgreSQL):
Recall
Keep this
Choosing the data store is a core system-design decision. SQL (relational) and NoSQL each fit different needs, and interviewers want you to justify the choice by the data shape, consistency needs, and scale — not by fashion.
| SQL (relational) | NoSQL | |
|---|---|---|
| Model | Tables, fixed schema, relations | Document / key-value / column / graph |
| Consistency | Strong (ACID) | Often eventual (BASE), tunable |
| Scaling | Vertical mostly; sharding is hard | Horizontal by design |
| Best for | Transactions, complex queries, joins | Huge scale, flexible schema, high write throughput |
| Examples | PostgreSQL, MySQL | MongoDB, Cassandra, DynamoDB, Redis |
Expected pattern: Every design round asks "which database and why?"; strong answers tie the choice to consistency and query needs.
Quick recap: SQL for ACID/joins/transactions; NoSQL for horizontal scale + flexible schema. Choose by data shape and access pattern; polyglot is fine.
You've read 0 of 6 steps
Now lock it in — questions straight after reading are what make it stick.