Module 51: Introduction to Databases
SQL and NoSQL
🏠The everyday picture
A library catalogue with strict cards for every book, versus a box of folders where each folder can hold whatever papers belong to that topic. Both have their uses; the catalogue is better for most libraries.
📘What it really is
- NoSQL is a name for databases that aren't relational. The main kinds:
- document databases (MongoDB, Firestore): store JSON-like documents; each can have a different shape; good when data is naturally nested and read as a whole;
- key-value stores (Redis): extremely fast lookups by key; great for caches, sessions and rate limits (Modules 44 and 48);
- wide-column (Cassandra): huge write volumes across many servers;
- graph databases (Neo4j): data that's mostly about connections, like social networks;
-
vector databases (or vector features in PostgreSQL): search by meaning for AI apps (Level 7).
-
Choosing:
- most business apps (customers, orders, payments, bookings) have clear structure and relationships: a relational database fits best, and PostgreSQL is a safe default;
- add a key-value store like Redis for caching or sessions when needed;
-
choose a document database when data is genuinely shapeless or document-like, not just to avoid designing tables.
-
PostgreSQL also stores JSON in columns (
jsonb), so you can mix strict tables with flexible fields where needed. - With AI: if an AI suggests MongoDB for an app full of relationships (orders, payments, customers), ask why; "flexibility" often turns into inconsistent data later.
🖱️Try it
For each of these, write which kind of database you'd choose and why: a booking system for a clinic; a cache of exchange rates; storing user-written blog posts with varying sections; a "people you may know" feature; a search that finds lessons similar in meaning to a question.
✅Quick check
Which kind of database is usually best for customers, orders and payments?
Show the answer
A relational database, such as PostgreSQL.
What's Redis commonly used for in web apps?
Show the answer
Caching, sessions and rate-limit counters: fast key-value lookups.
