SQL vs NoSQL
SQL databases store rows in tables with a fixed schema and a query language. NoSQL is a loose label for document, key-value, column, and graph stores that trade some relational features for flexibility or scale.
Detailed Explanation
A relational (SQL) database (PostgreSQL, MySQL, SQLite) models data as tables, primary keys, and foreign keys. You query with SQL: SELECT, JOIN, WHERE. Transactions (BEGIN / COMMIT) and constraints (UNIQUE, NOT NULL, CHECK) keep the data honest. Node talks to these through pg, mysql2, better-sqlite3, or an ORM.
Document stores (MongoDB, CouchDB, Firestore) persist JSON-like documents. Nested arrays live in the document instead of a child table. You query with a vendor API, not portable SQL. Schema is optional; a bad write still lands unless you add validation.
Key-value stores (Redis, DynamoDB in simple mode) get and set by key. Fast, limited query. Wide-column (Cassandra) and graph (Neo4j) are other NoSQL families with their own query languages.
The slogan "NoSQL scales, SQL does not" is outdated. Postgres shards and replicas exist. Mongo transactions exist. Pick by shape and invariants. Money, inventory, and users with lots of relations want SQL. A per-user JSON blob that is always read whole can be a document. A session or rate-limit counter is Redis. IndexedDB in the browser is a document/key store on the client, not a server.
JavaScript's JSON maps naturally onto documents. That convenience is why many Node tutorials start with Mongo. It is also why they later grow user.orders[i].items[j] instead of a join they should have had.
What it costs you: joining in the application (N+1 queries, inconsistent updates) when you picked documents for relational data, or fighting an ORM when you picked SQL for a blob. Migrations are the SQL tax; undocumented implicit schemas are the document tax.
Reach for SQL when you have relations and transactions. Reach for a document store when the document is the aggregate. Reach for Redis for ephemeral or high-churn keys. Reach for IndexedDB in the browser for offline caches.
Code Examples
SQL-shaped: two tables, a join
// SQL-shaped: two tables, a join
const sql = `
SELECT o.id, u.email
FROM orders o
JOIN users u ON u.id = o.user_id
WHERE o.id = $1
`;Document-shaped: one object
// Document-shaped: one object
const order = {
id: "o-1",
user: { email: "ada@example.com" },
items: [{ sku: "book", qty: 1 }],
};Key-value
// Key-value
await redis.set("session:abc", JSON.stringify({ userId: 7 }), "EX", 3600);Common Gotchas
"Schemaless" still has a schema in your code
a missing field is a production incident, not flexibility.
Multi-document updates without transactions race
SQL and Mongo both need an explicit transaction when two rows must change together.
JOINs in the app are still joins
three `find`s in a loop are slower and less atomic than one SQL query.
SQLite is SQL and can live in-process
do not assume SQL means a separate server.