Course Overview
Where SQL Is Used
Case studies of how large-scale companies like Amazon, Uber, and Netflix use relational databases.
Interview: System design interviews frequently require you to justify database choices using real-world case studies. Knowing how FAANG companies architect their SQL systems gives you concrete examples to reference.
1. Introduction
Almost every major technology company relies on relational databases at its core. Despite the hype around NoSQL and microservices, the fundamental business logic of most applications — orders, payments, user accounts, inventory — maps naturally to relational tables with strong consistency guarantees. This topic examines real-world case studies showing exactly how and why SQL powers the backbone of modern technology.
2. Why It Matters
Knowing where SQL is used in production helps you make better technology decisions, whether you are choosing a database for a startup, answering system design interview questions, or justifying an architecture decision to engineering leadership.
- System design interviews: FAANG companies expect you to reference real-world case studies (Amazon, Uber, Netflix) when justifying your database choices.
- Startup architecture: Starting with PostgreSQL avoids costly migrations later. Many startups begin with NoSQL and migrate to SQL after hitting consistency issues.
- Regulated industries: Healthcare (HIPAA), finance (SOX), and government (FedRAMP) all mandate SQL databases for audit trails and constraint enforcement.
Interview Insight
In system design interviews, always separate the transactional core (payments, orders) from the high-throughput stream (GPS pings, logs). Use SQL for the former and time-series/streaming systems for the latter.
3. Real-World Analogy
Imagine a busy restaurant kitchen. The head chef needs a reliable recipe book (the relational database) that guarantees every dish is made correctly — the right ingredients, in the right order, every time. The dishwashing station, however, just needs to process plates as fast as possible (like a key-value cache). Both are essential, but the recipe book is where the critical business logic lives.
SQL is the recipe book of modern applications. Every order, payment, and user transaction depends on its structured, reliable storage. Caching and streaming systems handle the high-speed peripheral tasks.
4. How It Works
Here are four industry case studies showing SQL in production:
Amazon E-Commerce: Orders, order_items, inventory, and payments tables linked via foreign keys. When an order is placed, stock is decremented atomically. If payment fails, the entire transaction rolls back — preventing orphaned orders or inventory inconsistencies.
Uber Trip System: Drivers, riders, trips, payments, and ratings tables form the transactional core. GPS telemetry uses specialized time-series storage (Schemaless), but payments, trip completion, and driver payouts require strict ACID guarantees via PostgreSQL.
Netflix Billing: Subscriptions, payment_methods, invoices, and plan_changes tables enforce billing correctness. The system must prevent double-charging, missed billing cycles, and wrong plan pricing after mid-cycle changes — all scenarios where SQL transaction isolation is critical.
Healthcare Records: Patients, diagnoses, prescriptions, allergies, and audit_log tables enforce HIPAA compliance. Database triggers automatically log every change. CHECK constraints prevent invalid medication dosages. UNIQUE constraints prevent duplicate patient records.
5. Internal Architecture
Production SQL architectures typically separate concerns across specialized systems, with the relational database at the core:
The primary handles all writes with ACID guarantees. Read replicas offload SELECT queries for reporting and analytics. WAL (Write-Ahead Log) replication ensures data consistency across replicas. Analytics queries run against a separate data warehouse to avoid impacting transactional performance.
6. Visual Explanation
The diagram shows how SQL databases sit at the center of production architectures, connected to caching layers (Redis), search engines (Elasticsearch), and data warehouses through well-defined data pipelines.
7. Practical Example
These examples show SQL in two very different industries — e-commerce and healthcare — both relying on the same core guarantees: atomic transactions and automatic audit logging.
8. Common Mistakes
- Designing entirely around NoSQL: Most applications never reach the scale where SQL becomes a bottleneck, but they always need data consistency. Start with SQL, add specialized systems only when needed.
- Storing relational data in a document store: You end up implementing JOINs in application code, losing database-level referential integrity and making queries harder to optimize.
- Using SQL for everything: High-throughput event streams, real-time analytics, and full-text search may benefit from specialized systems even within a SQL-primary architecture.
Common Pitfall
Many startups begin with NoSQL for "flexibility" but migrate to SQL once they hit production issues with data consistency, complex reporting, and regulatory compliance. Understanding when SQL is needed from day one saves costly migrations.
9. Quick Quiz
Q1: Why does Uber use PostgreSQL for payments but a specialized system for GPS data?
A) GPS data is structured and needs SQL constraints
B) Payments require ACID atomicity; GPS telemetry is high-throughput time-series data
C) PostgreSQL cannot store geographic coordinates
D) GPS data requires graph database traversal
Answer: B) Different consistency and throughput requirements
Q2: Which industry has the strictest SQL requirements?
A) Gaming
B) Social Media
C) Healthcare (HIPAA requires audit trails for every record change)
D) E-commerce
Answer: C) Healthcare — HIPAA mandates audit trails and constraint enforcement
10. Scenario-Based Challenge
Challenge: Design a Food Delivery Platform Database
Design a 4-table schema (restaurants, menu_items, orders, order_items) for a food delivery platform. Handle: (1) atomic stock/decrement when an order is placed, (2) foreign key constraints preventing orders for non-existent restaurants, (3) CHECK constraints ensuring positive prices and quantities. Write the DDL and one transactional INSERT that creates a complete order.
11. Debugging Exercise
This e-commerce checkout code sometimes allows overselling. Why?
Fix: Use SELECT ... FOR UPDATE to lock the row, or use UPDATE inventory SET stock = stock - 1 WHERE product_id = 101 AND stock >= 1 and check that exactly 1 row was affected.
12. Interview Questions
Q: How does Amazon handle order processing with relational databases?
A: Amazon uses a relational database for the order transaction core. When an order is placed, the system atomically: creates the order record, decrements inventory, processes payment, and updates order status — all within a single transaction. If any step fails, everything rolls back, preventing orphaned orders or inventory inconsistencies.
Q: Why do healthcare systems require SQL databases?
A: HIPAA compliance requires: (1) audit trails logging every read/write/delete on patient records, (2) constraint enforcement preventing invalid medication dosages, (3) referential integrity linking diagnoses to patients and physicians. SQL triggers, CHECK constraints, and foreign keys provide these guarantees at the database level — impossible to enforce reliably in application code alone.
Q: What is the typical production architecture around a SQL database?
A: Primary handles writes with ACID guarantees. Read replicas offload SELECT queries. WAL replication ensures consistency. Connection pools (PgBouncer) manage concurrent connections. Analytics queries run against a separate data warehouse (Snowflake, BigQuery) to avoid impacting transactional performance.
13. Production Considerations
- Separation of concerns: Use SQL for transactional data, Redis for caching, Elasticsearch for full-text search, and a data warehouse for analytics. Define clear data ownership per system.
- Connection pooling: Production systems need PgBouncer or HikariCP to manage 20-50 concurrent connections. Unpooled connections exhaust database resources under load.
- Read replicas: Route SELECT queries to read replicas to reduce primary load. Write queries (INSERT/UPDATE/DELETE) must always go to the primary. Monitor replication lag to prevent stale reads.
- Compliance automation: Use database triggers and CHECK constraints to enforce regulatory requirements at the database layer — not just in application code where they can be bypassed.
Use Cases
System design interviews: Reference Amazon, Uber, and Netflix case studies when explaining your database architecture choices
Startup architecture: Start with PostgreSQL for the transactional core and add specialized systems (Redis for caching, Elasticsearch for search) only when needed
Compliance-heavy industries: Healthcare, finance, and government systems require audit trails, constraint enforcement, and ACID guarantees that only SQL databases provide
Common Mistakes
Designing a system entirely around NoSQL because it "scales" — most applications never reach the scale where SQL becomes a bottleneck, but they always need data consistency
Storing relational data in a document store — you end up implementing JOINs in application code, losing database-level referential integrity
Using SQL for everything — high-throughput event streams, real-time analytics, and full-text search may benefit from specialized systems even within a SQL-primary architecture