SQL vs NoSQL Databases
A team building a chat app hears that "NoSQL scales better" and moves everything, including billing, into a document store. Six months later they are writing code by hand to keep invoice totals consistent. Neither family is better in general; each is better at particular jobs.
The rule
SQL: declare the shape, ask anything. NoSQL: design for the access, scale out.
SQL databases are relational: fixed tables, keys linking them, and one standard language for any question. You design the shape of the data, and queries adapt to it.
NoSQL is a loose name for databases that are not built around relational tables. There are four big families:
| Family | Stores | Good at | Example |
|---|---|---|---|
| Key-value | a value per key | very fast lookups by key | Redis |
| Document | JSON-like documents | records with varying shape | MongoDB |
| Wide-column | rows with flexible column sets | huge write volumes | Cassandra |
| Graph | nodes and edges | following relationships | Neo4j |
With NoSQL you usually start from the question — "load a user's profile by id" — and shape the data so that one question is cheap. Data is often duplicated on purpose. Many NoSQL systems were built to spread across many machines easily, and some relax consistency to do so, though modern ones increasingly offer transactions too.
"NoSQL" does not mean "no query language" — most have one; it is just not SQL. And the line is blurring: PostgreSQL can store JSON documents, and some NoSQL stores accept SQL-like queries.
The shortcut
Name the question before you pick the store. Write down the main way the data will be read, then match it:
- Must be correct and questioned in many ways → relational
- Fetched by one key, very fast → key-value
- Each record has its own shape, read as a whole → document
- The question is about connections → graph
Orders and payments
Must be correct, and analysts will slice them many ways. Relational.
The trap: choosing a store for its reputation instead of for the question it must answer.
Drills
Answer fast — trust the rule.
Session tokens are looked up by token millions of times a day and expire after 30 minutes. Which store fits best?
Which statement about NoSQL is true?
A general ledger where every debit must match a credit, audited yearly in new ways. Best default?
A social app's main query is "friends of my friends who live in my city". Which family is designed for this?
Remember
- SQL: declare the shape, ask anything. NoSQL: design for the access, scale out.
- Name the question before you pick the store.
- NoSQL is a family of designs, not "no queries" and not automatically faster.
