Module 3 · Database designLesson 22 of 887 minIntermediate

SQL vs NoSQL

SQL databases store tidy tables and answer any question. NoSQL databases store data shaped for specific questions and spread out easily.

Try it

Load a profile from both databases, then run "Report" and "New field" and compare which one finds each job easy.

Relational (SQL) databases

PostgreSQL, MySQL and SQL Server store data in tables with fixed columns. Related data is linked by ids and combined with joins.

  • Schema: the database enforces what each row looks like, so bad data is rejected.
  • Transactions: several changes succeed or fail together (more soon).
  • Flexible queries: any question can be asked with SQL, even ones you didn't plan for.
  • Scaling: easy to scale up and add read replicas; splitting writes across machines takes more work.

NoSQL databases

"NoSQL" covers several different designs:

TypeStoresGood forExamples
DocumentJSON-like documentsObjects read as a whole, changing shapesMongoDB, Firestore
Key-valueA value per keyVery fast lookups, caches, sessionsRedis, DynamoDB
Wide-columnRows with many columns, partitionedHuge write-heavy data, time seriesCassandra, Bigtable
GraphNodes and relationshipsFollowing connectionsNeo4j

Most were built to spread across many machines from day one, and to be fast for known access patterns. The trade-off is usually weaker joins, more limited transactions, or eventual consistency.

How to choose

Ask:

  1. What are the main reads and writes? If the page always loads "a user with their settings", a document fits. If you need reports across everything, SQL fits.
  2. How much does correctness matter? Money and inventory want strong transactions.
  3. How big, how fast? Millions of writes a second across regions may need a distributed NoSQL store.

A good default for a new product is a relational database. Many big systems use both: SQL for core records, plus a key-value store for caching and a search engine for text search.

Quick check

You're building a banking ledger that needs strict transactions and flexible reports. What's the usual choice?