Databases · Question 25 of 50
SQL or NoSQL: how do you choose?
Data modelling trade-offs, not fashion.
The answer
Relational databases (PostgreSQL, MySQL) have tables with a schema, joins and strong transactions: best when the data is related and correctness matters, such as orders, payments and stock.
NoSQL is several families: documents (MongoDB) for nested records read together, key-value (Redis, DynamoDB) for fast lookups by key, wide-column (Cassandra) for very high write volumes, graphs (Neo4j) for relationships. They often scale out more easily, but you model around your queries and give up some joins and transactions. Start relational; choose NoSQL for a specific access pattern or scale, not because it is "schemaless".
The picture
joins and transactions? ──▶ SQL one nested record by its id? ──▶ documents cache, counters, sessions? ──▶ key-value huge write volume, simple reads? ──▶ wide-column friends of friends? ──▶ graph
Can MongoDB do transactions?
Show the answer
Yes, across documents since version 4.0. But if you need them everywhere, a relational model may fit better.