📝 Final Quiz: Production & Architecture (Chapters 30-35)

1. What is the 3-2-1 backup rule?

2. Why should you NEVER concatenate user input into SQL strings?

3. What's the optimal connection pool size for a 4-core server?

4. What does CREATE INDEX CONCURRENTLY do differently?

5. What is the "cache stampede" problem?


Chapter 36: Choosing the Right Database for Your System

This final chapter ties everything together. Given a system to build, how do you pick the right database(s)?

The Decision Framework

Step 1: What's your data model? Structured with relationships → Relational (PostgreSQL) Documents with varying schema → Document (MongoDB) Simple key lookups → Key-Value (Redis) Highly connected data → Graph (Neo4j) Time-stamped metrics → Time-Series (TimescaleDB) Step 2: What are your access patterns? Read-heavy → Add read replicas + caching Write-heavy → Consider LSM-tree (Cassandra) or partitioning Mixed OLTP → PostgreSQL handles this well Analytics → Column-store (ClickHouse) or data warehouse Step 3: What are your scale requirements? < 1TB, < 10K QPS → Single PostgreSQL (seriously, this handles a LOT) 1-10TB → PostgreSQL with partitioning + read replicas > 10TB or > 100K QPS → Distributed DB or sharding Step 4: What are your consistency requirements? Financial/critical → Strong consistency (PostgreSQL, CockroachDB) Social/content → Eventual consistency acceptable (Cassandra, DynamoDB)

Common Architecture Patterns

Pattern 1: Simple Web App

App → PostgreSQL
That's it. Don't over-engineer.

Pattern 2: High-Traffic Web App

App → Redis (cache) → PostgreSQL (primary) → PostgreSQL (read replicas)
Cache hot data, scale reads with replicas.

Pattern 3: Microservices (Telecom CNF)

Service A → PostgreSQL A (sessions)
Service B → Redis (state cache) + PostgreSQL B (config)
Service C → TimescaleDB (metrics/telemetry)
All → Kafka (event streaming between services)

Pattern 4: Analytics Platform

OLTP: PostgreSQL (operational data)
  → CDC (Change Data Capture) →
OLAP: ClickHouse (analytics queries on billions of rows)

The Golden Rules

💡 Database Selection Rules
  1. Start with PostgreSQL until you have a measured reason not to
  2. Add Redis when you need caching or sub-millisecond lookups
  3. Add a specialized DB only when PostgreSQL demonstrably can't handle the workload
  4. Polyglot persistence (multiple DBs) adds operational complexity — justify it
  5. Your team's expertise matters — a well-operated MySQL beats a poorly-operated CockroachDB

What You've Learned

You now understand:

🎓 Congratulations!

You've completed the Database Zero to Hero guide. You now have the knowledge to design, query, optimize, and operate databases at a professional level. The next step is practice — build something, run queries, break things, fix them. The concepts in this guide will serve you for your entire career.