Course Overview
Why SQL Still Dominates
A comparison of SQL vs NoSQL, key-value stores, and graph databases in production environments.
Interview: Senior engineers are expected to justify technology choices. Interviewers ask "Why PostgreSQL over MongoDB?" to test whether you understand the trade-offs between consistency, scalability, and query flexibility.
1. Introduction
In the late 2000s, a wave of NoSQL databases emerged — MongoDB, Cassandra, Redis, Neo4j — each promising to "replace" SQL databases. Yet in 2026, PostgreSQL and MySQL remain the default choice for most production systems. SQL did not dominate by accident; it dominates because most business requirements demand strong consistency and flexible querying — guarantees that NoSQL databases trade away for scalability or schema flexibility.
This topic examines why SQL remains the dominant database technology through the lens of the CAP theorem, production trade-offs, and the modern convergence of multi-model databases.
2. Why It Matters
Senior engineers are expected to justify technology choices with evidence, not opinions. When an interviewer asks "Why PostgreSQL over MongoDB?", the answer must address consistency guarantees, query patterns, and operational complexity — not just personal preference.
- Architecture decisions: Choosing the wrong database can lead to data corruption, overselling, or months of migration work.
- Cost implications: Running both PostgreSQL and MongoDB means maintaining, monitoring, and backing up two separate systems — doubling operational overhead.
- Team expertise: SQL has a 40-year talent pool. Finding engineers who can write optimized SQL queries is significantly easier than finding specialists for newer NoSQL technologies.
Interview Insight
When asked "SQL vs NoSQL", avoid saying one is "better." Frame your answer around: (1) consistency requirements, (2) query patterns, and (3) operational expertise. This demonstrates engineering maturity over tribal loyalty to any technology.
3. Real-World Analogy
Think of SQL as a bank and NoSQL as a mattress stash. A bank guarantees that when you transfer money, both the debit and credit happen atomically — the money is never lost or duplicated. A mattress stash lets you hide cash quickly and retrieve it fast, but there’s no ledger, no transaction history, and no guarantee that two people won’t grab the same stack simultaneously.
For most businesses, the bank model is essential. For a few specific use cases (caching, sensor data), the mattress approach works better. The key is knowing which model your application needs.
4. How It Works
The CAP theorem (Eric Brewer, 2000) states that a distributed system can guarantee at most two of three properties:
- Consistency (C): Every read returns the most recent write (or an error).
- Availability (A): Every request receives a response (no guarantee it is the latest data).
- Partition Tolerance (P): The system continues operating despite network failures between nodes.
| Database Type | CAP Position | Trade-off |
|---|---|---|
| SQL (single node) | CA | Consistency + Availability; fails on network partition |
| Cassandra | AP | Availability + Partition Tolerance; eventual consistency |
| MongoDB | CP (tunable) | Configurable consistency; sacrifices availability under partitions |
Most business systems cannot tolerate eventual consistency. If a bank transfer is eventually consistent, you might see money disappear for seconds or minutes — an unacceptable user experience and a regulatory violation.
5. Internal Architecture
SQL and NoSQL databases have fundamentally different internal architectures optimized for their respective consistency models:
The SQL architecture prioritizes correctness first — every write is logged to the WAL before acknowledgment, ensuring crash recovery and transaction durability. NoSQL architectures prioritize throughput first — writes are buffered in memory and flushed asynchronously, trading durability guarantees for raw speed.
6. Visual Explanation
The diagram compares SQL and NoSQL architectures side-by-side, showing how SQL prioritizes consistency through WAL-based crash recovery while NoSQL optimizes for throughput through LSM-tree-based writes.
7. Practical Example
Modern PostgreSQL blends relational integrity with NoSQL-style flexibility via JSONB. You get ACID transactions and schemaless document storage in a single system — this is why SQL databases are absorbing many NoSQL use cases.
8. Common Mistakes
- Choosing NoSQL because "it scales better": Horizontal scaling of SQL databases is well-understood (read replicas, Citus, Vitess) and sufficient for most workloads. Don’t sacrifice consistency for scale you may never need.
- Using MongoDB for data that requires JOINs: You end up implementing joins in application code, which is slower and harder to maintain than native SQL JOINs.
- Ignoring operational complexity: Running PostgreSQL + Redis + MongoDB means maintaining, monitoring, and backing up three separate systems. PostgreSQL’s JSONB, full-text search, and caching extensions can often consolidate this into one.
Common Pitfall
"NoSQL" does not mean "no SQL." Many NoSQL databases now support SQL-like query syntax (Cassandra’s CQL, MongoDB’s aggregation pipeline). The real distinction is the data model and consistency guarantees, not the query language.
9. Quick Quiz
Q1: What does the CAP theorem state?
A) A database can be fast, cheap, and reliable simultaneously
B) A distributed system can guarantee at most 2 of 3 properties: Consistency, Availability, Partition Tolerance
C) All databases eventually converge to the same consistency model
D) SQL databases are always faster than NoSQL databases
Answer: B) At most 2 of 3: C, A, or P
Q2: Which database type provides the strongest consistency guarantees?
A) Redis (key-value store)
B) Cassandra (wide-column store)
C) PostgreSQL (relational)
D) Neo4j (graph database)
Answer: C) PostgreSQL — full ACID with serializable isolation
Q3: When is NoSQL a better choice than SQL?
A) Financial transaction processing
B) High-throughput event ingestion (millions of sensor readings/sec)
C) Complex reporting with multi-table joins
D) Applications requiring foreign key constraints
Answer: B) High-throughput event ingestion
10. Scenario-Based Challenge
Challenge: The E-Commerce Platform Decision
You are building an e-commerce platform with: (1) product catalog with flexible attributes, (2) shopping cart with real-time stock updates, (3) order processing with payment guarantees, (4) recommendation engine based on purchase history.
For each component, choose SQL or NoSQL and justify your decision based on consistency requirements, query patterns, and scaling needs. Can PostgreSQL’s JSONB handle the product catalog alone, eliminating the need for MongoDB?
11. Debugging Exercise
A team migrated from PostgreSQL to MongoDB for their order system. Now they’re seeing occasional duplicate order IDs. Can you identify why?
Fix: Use PostgreSQL’s SERIAL or SEQUENCE with UNIQUE constraints, or wrap the MongoDB operations in a multi-document transaction (available in MongoDB 4.0+, but with significant performance overhead).
12. Interview Questions
Q: Why do most fintech companies use SQL databases?
A: Financial transactions require ACID guarantees — specifically atomicity (a transfer either fully happens or doesn’t) and isolation (concurrent transfers don’t interfere). SQL databases provide multi-row, multi-table transactions with serializable isolation. NoSQL alternatives either lack these guarantees or require complex application-level coordination.
Q: When would you recommend Cassandra over PostgreSQL?
A: Cassandra excels at write-heavy workloads with time-series data (IoT sensor readings, log aggregation) where eventual consistency is acceptable. Its LSM-tree architecture and gossip-based replication handle millions of writes per second across globally distributed nodes — a workload where PostgreSQL’s synchronous replication would become a bottleneck.
Q: How has PostgreSQL absorbed NoSQL use cases?
A: PostgreSQL’s JSONB column type provides schemaless document storage with GIN indexes. Full-text search rivals Elasticsearch for many use cases. PostGIS handles geospatial queries. Arrays, ranges, and hstore cover additional NoSQL niches — all within ACID-guaranteed transactions.
13. Production Considerations
- Polyglot persistence: Large systems often use multiple database types — PostgreSQL for transactional data, Redis for caching, Elasticsearch for search. The key is defining clear boundaries and data ownership per service.
- Migration costs: Switching from SQL to NoSQL (or vice versa) after launch is extremely expensive. Schema redesign, query rewrites, data migration, and team retraining can take months. Choose correctly from the start.
- PostgreSQL as the default: Unless you have a specific workload that demands NoSQL (millions of writes/sec, graph traversal, schemaless catalogs), start with PostgreSQL. Its JSONB, full-text search, and PostGIS extensions cover most NoSQL use cases.
- Monitoring consistency: In distributed SQL deployments (Citus, CockroachDB, YugabyteDB), monitor replication lag and consistency guarantees. Even "strongly consistent" distributed databases have edge cases under network partitions.
Use Cases
Technology selection: Justifying PostgreSQL/MySQL over MongoDB when presenting architecture decisions to engineering leadership
System design interviews: Choosing the right database for each microservice based on consistency, query pattern, and scaling requirements
Legacy migration: Moving from monolithic SQL to polyglot persistence where different services use the database type that fits their workload
Common Mistakes
Choosing NoSQL because "it scales better" — horizontal scaling of SQL databases is well-understood (read replicas, Citus, Vitess) and sufficient for most workloads
Using MongoDB for data that requires complex JOINs — you end up implementing joins in application code, which is slower and harder to maintain than SQL
Ignoring operational complexity — running both PostgreSQL and Redis/MongoDB/Elasticsearch means maintaining, monitoring, and backing up three separate systems