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.
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:
| Type | Stores | Good for | Examples |
|---|---|---|---|
| Document | JSON-like documents | Objects read as a whole, changing shapes | MongoDB, Firestore |
| Key-value | A value per key | Very fast lookups, caches, sessions | Redis, DynamoDB |
| Wide-column | Rows with many columns, partitioned | Huge write-heavy data, time series | Cassandra, Bigtable |
| Graph | Nodes and relationships | Following connections | Neo4j |
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:
- 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.
- How much does correctness matter? Money and inventory want strong transactions.
- 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.