| Users / Traffic | Data Size | Query Load | System Changes |
|---|---|---|---|
| 100 users | Small (MBs) | Low (few QPS) | Single DB instance, simple indexing |
| 10,000 users | Medium (GBs) | Moderate (hundreds QPS) | Read replicas, connection pooling, optimized queries |
| 1,000,000 users | Large (TBs) | High (thousands QPS) | Sharding, caching layers, partitioning, load balancing |
| 100,000,000 users | Very Large (PBs) | Very High (tens of thousands QPS) | Multi-region clusters, advanced sharding, distributed transactions, strong caching/CDN |
Relational database strengths in HLD - Scalability & System Analysis
At small to medium scale, the database CPU and disk I/O become the first bottleneck because relational databases rely on complex joins and ACID transactions that consume CPU and disk resources.
As traffic grows, connection limits and query latency increase, causing slow responses.
- Vertical scaling: Upgrade server CPU, RAM, and faster disks to handle more queries.
- Read replicas: Offload read queries to replicas to reduce load on primary DB.
- Connection pooling: Reuse DB connections to reduce overhead.
- Caching: Use in-memory caches (e.g., Redis) for frequent queries to reduce DB hits.
- Sharding: Split data horizontally across multiple DB instances by key ranges or user IDs.
- Partitioning: Divide large tables into smaller parts to improve query performance.
- Load balancing: Distribute traffic evenly across app servers and DB replicas.
- Multi-region deployment: Place DBs closer to users to reduce latency.
Assuming 1 million users with 1 request per second each:
- Requests per second: ~1,000,000 QPS (too high for single DB)
- Single PostgreSQL instance handles ~5,000 QPS → need ~200 DB instances or heavy caching
- Storage: 1 TB data growing at 10 GB/day requires scalable storage solutions
- Network bandwidth: 1 Gbps = 125 MB/s, so multiple network interfaces or cloud bandwidth needed
Start by explaining the strengths of relational databases: strong consistency, ACID transactions, and complex queries.
Then discuss how these strengths impact scaling: joins and transactions add CPU and I/O load.
Outline bottlenecks clearly and propose solutions step-by-step: vertical scaling, read replicas, caching, sharding.
Use real numbers to show understanding of limits and trade-offs.
Question: Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first and why?
Answer: Add read replicas to offload read queries and implement connection pooling to reduce overhead. This addresses the immediate CPU and connection bottlenecks without major redesign.
Practice
Solution
Step 1: Understand relational database data organization
Relational databases organize data in tables with relationships, which helps maintain consistency.Step 2: Identify the strength related to multi-user access
They support multiple users accessing and modifying data while keeping it accurate and consistent.Final Answer:
They ensure strong data consistency across multiple users. -> Option BQuick Check:
Data consistency = C [OK]
- Confusing relational with document databases
- Thinking relational databases store unstructured data
- Assuming relational databases don't support complex queries
Solution
Step 1: Recall SQL keywords for combining tables
The JOIN keyword is used to combine rows from two or more tables based on a related column.Step 2: Differentiate from other SQL commands
SELECT retrieves data, INSERT adds data, UPDATE modifies data, but JOIN combines tables.Final Answer:
JOIN -> Option DQuick Check:
Combine tables = JOIN [OK]
- Confusing SELECT with JOIN
- Using INSERT or UPDATE to combine tables
- Not knowing JOIN syntax
Users and Orders, what will the following SQL query return?SELECT Users.name, Orders.id FROM Users JOIN Orders ON Users.id = Orders.user_id;
Solution
Step 1: Analyze the JOIN condition
The query joins Users and Orders where Users.id equals Orders.user_id, linking users to their orders.Step 2: Understand the SELECT output
It selects user names and order IDs only for matching pairs, so users without orders are excluded.Final Answer:
All users with their order IDs where user IDs match -> Option AQuick Check:
JOIN with ON = matched user-orders [OK]
- Thinking JOIN returns all users or all orders
- Assuming WHERE clause is mandatory for JOIN
- Confusing JOIN with UNION
SELECT Customers.name, Orders.id FROM Customers JOIN Orders;
Solution
Step 1: Check JOIN syntax
JOIN requires an ON clause to specify how tables relate; missing ON causes error or unintended Cartesian product.Step 2: Confirm other parts are correct
SELECT is correct for fetching data; assuming Orders table exists; so error is missing ON clause.Final Answer:
Missing ON clause to specify join condition -> Option CQuick Check:
JOIN needs ON clause [OK]
- Assuming JOIN works without ON
- Confusing SELECT with INSERT
- Ignoring table existence
Solution
Step 1: Understand multi-user data update needs
Multiple users updating data require mechanisms to avoid conflicts and keep data accurate.Step 2: Identify relational database feature for consistency
ACID transactions ensure atomicity, consistency, isolation, and durability, preventing data loss or corruption.Final Answer:
ACID transactions ensuring data consistency -> Option AQuick Check:
Multi-user accuracy = ACID transactions [OK]
- Confusing NoSQL features with relational strengths
- Thinking JSON storage ensures consistency
- Ignoring transaction properties
Ready to prove it?
Pass the test and this pattern moves unknown
