Databases Lesson 1: What are Databases?
A database is an organized collection of data. Without databases, nothing on the web would persist. Every app — Twitter, Netflix, your bank — runs on one.
Types of Databases
// Relational (SQL): structured, tables, strict schema
// PostgreSQL, MySQL, SQLite, Microsoft SQL Server
// Use for: user data, orders, transactions, anything relational
// Document (NoSQL): flexible JSON-like documents
// MongoDB, CouchDB, Firestore
// Use for: content, catalogs, user profiles with varying fields
// Key-Value: ultra-fast simple lookups
// Redis, DynamoDB, Memcached
// Use for: caching, sessions, real-time data, queues
// Graph: relationships between entities
// Neo4j, Amazon Neptune
// Use for: social networks, recommendation engines
// Time-Series: data points over time
// InfluxDB, TimescaleDB
// Use for: metrics, monitoring, IoT data
SQL vs NoSQL Trade-offs
// SQL:
// ✅ ACID transactions (Atomicity, Consistency, Isolation, Durability)
// ✅ Powerful joins and queries
// ✅ Strict schema catches errors
// ❌ Scaling out is harder
// ❌ Schema changes require migrations
// NoSQL:
// ✅ Flexible schema (no migrations for simple changes)
// ✅ Horizontal scaling
// ✅ Fast for document reads
// ❌ No joins (manual in code)
// ❌ Consistency trade-offs (CAP theorem)
🏋️ Practice Task
Map these apps to database types: Instagram posts, Uber driver locations, bank transfers, Netflix recommendations, shopping cart sessions, GitHub code search, chat messages, medical records. Explain your choice for each.
💡 Hint: Multiple databases often used together: Redis for sessions, PostgreSQL for user data, Elasticsearch for search.