Databases & SQL

Lesson 6 of 7

Lesson 6 — SQL vs NoSQL: Choosing the Right Store

Document, key-value, graph, column and time-series databases — and when each one wins.

🟡 Intermediate 90 XP

Learn it

Relational (SQL) databases store rows in fixed tables with strong rules: PostgreSQL, MySQL, SQLite, SQL Server, Oracle.

Document stores (MongoDB, Firestore) keep flexible JSON-like documents — great when the shape of data varies.

Key-value stores (Redis) are ultra-fast lookups by key, perfect for caches, sessions and leaderboards.

Graph databases (Neo4j) store relationships as first-class things — ideal for social networks and fraud rings.

Column stores (BigQuery, ClickHouse) crunch analytics over billions of rows; time-series stores (InfluxDB) handle sensor data.

Key terms

Relational DB
Tables, rows, SQL, strong schema and ACID guarantees.
Document store
Stores JSON-like documents with flexible structure.
Key-value store
Fast get/set by unique key; used for caches and sessions.
Graph database
Stores nodes and edges; queries traverse relationships fast.
Eventual consistency
Replicas converge over time rather than instantly.

Pick a store for each job

  1. 1Bank ledger: Relational — transactions and ACID are non-negotiable.
  2. 2Game leaderboard: Redis sorted sets — millisecond ranking updates.
  3. 3Product catalogue with varied attributes: Document store — every category has different fields.
  4. 4'People you may know': Graph database — multi-hop relationship traversal.
  5. 5IoT sensor readings: Time-series database — huge append-only writes, time-window queries.

Same question, three languages

sql-- SQL (PostgreSQL)
SELECT name FROM player WHERE score > 9000 ORDER BY score DESC LIMIT 10;

-- MongoDB aggregation
db.player.find({ score: { $gt: 9000 } }).sort({ score: -1 }).limit(10)

-- Cypher (Neo4j): friends-of-friends, awkward in SQL
MATCH (me:Player {name:'Ana'})-[:FRIEND*2]->(fof)
WHERE NOT (me)-[:FRIEND]->(fof)
RETURN DISTINCT fof.name LIMIT 10;

Simple filtering looks similar everywhere. The difference shows up on relationship-heavy questions, where Cypher stays short and SQL needs repeated self-joins.

Try it

Match the workload to the best-fit database type.

Bank transfers
Session cache
Friend recommendations
Analytics over 5bn rows
Varied product attributes

Challenge

A startup builds a food delivery app: orders and payments, live courier locations every 3 seconds, restaurant menus that differ wildly, and a 'popular near you' feed. Recommend a database for each workload and justify the trade-offs.

Pick whichever way suits you — every mode earns the same bonus XP.

Write at least 40 more characters to submit.

Mark your own work

Guided walkthrough — 0/3 clues revealed

  1. Clue 1 locked — reveal it only if you get stuck.
  2. Clue 2 locked — reveal it only if you get stuck.
  3. Clue 3 locked — reveal it only if you get stuck.

Each clue costs 5 XP (never below 23 XP). You'd earn 45 XP right now.

Quiz time

Question 1 of 4Score 0

Which store is best for millisecond leaderboards?