Loading…
Loading…
Charting your lesson…
Opening your lesson…
SQL vs NoSQL Databases
Lesson 3 of 6
Choosing between relational (SQL) and non-relational (NoSQL) databases based on schema, consistency, and scale needs.
6 steps•about 10 min•8 flashcards
Step 1/ 61 min
"Which database would you pick, and why?" is a near-guaranteed follow-up in any design round. A crisp SQL-vs-NoSQL answer that ties choice to requirements — not fashion — signals real engineering judgment.
Step 2/ 61 min
SQL (relational) databases store data in tables of rows and columns with a fixed schema and relationships enforced by keys. They speak SQL and offer strong ACID transactions. NoSQL (non-relational) databases relax the rigid schema to gain flexibility and horizontal scale; they come in families — document, key-value, wide-column, and graph. The right choice follows your data shape, consistency needs, and scale.
SQL examples: PostgreSQL, MySQL, Oracle. Data is normalized across related tables; you JOIN to combine them. NoSQL examples: MongoDB (document), Redis/DynamoDB (key-value), Cassandra (wide-column), Neo4j (graph). Data is often denormalized and stored together for fast reads.
SQL databases prize ACID (Atomicity, Consistency, Isolation, Durability) — transactions are all-or-nothing and leave the DB consistent. Many NoSQL systems favor BASE (Basically Available, Soft state, Eventual consistency) — they stay available and scalable, accepting that replicas may briefly disagree before converging. This is the fundamental trade: strong consistency vs availability at scale.
SQL scales primarily vertically and via read replicas; sharding it is possible but complex because of cross-shard JOINs and transactions. Many NoSQL stores are built to scale horizontally from day one, partitioning data across nodes. SQL's fixed schema enforces integrity but makes changes heavier; NoSQL's flexible schema lets each record differ, great for evolving or varied data but pushing validation into the application. NoSQL is not "schema-less" so much as "schema-on-read."
Step 3/ 61 min
Designing an e-commerce app: orders, payments and inventory need multi-row transactions and strict integrity, so a relational database (PostgreSQL) fits. The product catalog with varied, nested attributes and huge read volume fits a document store (MongoDB), and the shopping-cart and session data fit a key-value store (Redis). Real systems mix databases — polyglot persistence — picking the right tool per workload.
Step 4/ 61 min
Choose SQL when you need strong transactions, complex queries/JOINs, and well-structured, relational data (finance, orders, bookings). Choose NoSQL when you need massive horizontal scale, flexible/evolving schemas, or a specific access pattern (key lookups, documents, graphs, time series).
Step 5/ 61 min
Anchor it as "SQL = Structure + Strong consistency; NoSQL = Not-only-SQL, Scale + flexibility." If the interviewer stresses transactions and integrity, lean SQL; if they stress scale and flexible data, lean NoSQL.
Don't claim "NoSQL scales, SQL doesn't." SQL databases scale well vertically and with replicas and handle enormous workloads; the real difference is horizontal scaling and schema flexibility, not raw capability.
Step 6/ 6· Worked examples1 min
Problem
Choose a database type for (a) a bank's transaction ledger and (b) a social app's activity feed taking ~1,000,000 writes/second. Justify each choice.
Try it on paper first.
Recall
Keep this
Fast revision of choosing a database.
You've read 0 of 6 steps
Now lock it in — questions straight after reading are what make it stick.