| Users / Data Size | 100 Users | 10K Users | 1M Users | 100M Users |
|---|---|---|---|---|
| Data Volume | Small (MBs) | Medium (GBs) | Large (TBs) | Very Large (PBs) |
| Database Load | Low QPS (queries/sec) | Moderate QPS | High QPS | Very High QPS |
| Response Time | Fast (ms) | Acceptable (tens ms) | Slower (hundreds ms) | Slow (seconds) |
| Storage Needs | Minimal | Growing | Large Disk Arrays | Distributed Storage Systems |
| Backup & Recovery | Simple | Scheduled | Complex | Highly Automated |
Why database scaling handles data growth in HLD - Scalability Evidence
As data grows, the database storage and query speed become the first limits. Large data slows down searches and updates. Disk space fills up. Indexes become less efficient. This causes slower responses and higher load on the database server.
- Vertical Scaling: Upgrade to bigger servers with more CPU, RAM, and faster disks to handle more data and queries.
- Read Replicas: Create copies of the database to spread read queries and reduce load on the main database.
- Sharding: Split data horizontally across multiple database servers by user ID or other keys to distribute storage and queries.
- Caching: Use in-memory caches like Redis to store frequent query results and reduce database hits.
- Archival: Move old or less-used data to cheaper storage to keep the main database smaller and faster.
Assuming 1M users generate 10 QPS each, total 10M QPS is unrealistic for one DB. A single PostgreSQL instance handles ~5K QPS. So, 10M QPS requires ~2000 DB instances or sharding.
Storage: 1M users with 1GB each = 1PB data. This needs distributed storage solutions.
Bandwidth: 1 Gbps network supports ~125 MB/s. Large data transfers require multiple network interfaces or data centers.
Start by explaining how data growth affects storage and query speed. Identify the first bottleneck (usually DB storage or query load). Then discuss vertical scaling, read replicas, sharding, and caching as solutions. Mention trade-offs and complexity added by each.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first and why?
Practice
Solution
Step 1: Understand the purpose of scaling
Database scaling is used to handle more data without slowing down or losing reliability.Step 2: Identify the correct goal
The main goal is to keep data access fast and reliable as data grows.Final Answer:
To keep data access fast and reliable -> Option AQuick Check:
Scaling improves speed and reliability [OK]
- Thinking scaling reduces data size
- Believing scaling deletes old data
- Assuming scaling makes data harder to access
Solution
Step 1: Define vertical scaling
Vertical scaling means improving one server's hardware like CPU or RAM.Step 2: Match the option to vertical scaling
Upgrading a server with better CPU and RAM fits vertical scaling.Final Answer:
Upgrading a server with a faster CPU and more RAM -> Option BQuick Check:
Vertical scaling = better single server [OK]
- Confusing vertical with horizontal scaling
- Thinking adding servers is vertical scaling
- Mixing sharding with vertical scaling
Solution
Step 1: Understand sharding
Sharding splits data across multiple servers or shards to spread load.Step 2: What happens when one shard is full?
New shards are added to hold more data and keep performance.Final Answer:
New shards are added to distribute the data load -> Option DQuick Check:
Sharding adds shards as data grows [OK]
- Thinking data is deleted when shard is full
- Believing replication happens on same shard
- Assuming system slows down without adding shards
Solution
Step 1: Understand replication purpose
Replication copies data to replicas for speed and backup.Step 2: Identify misconfiguration effects
If replication is wrong, replicas may not match primary, causing inconsistency.Final Answer:
Data inconsistency between primary and replicas -> Option AQuick Check:
Replication errors cause inconsistency [OK]
- Thinking replication speeds up writes
- Assuming replicas get deleted automatically
- Confusing sharding with replication
Solution
Step 1: Analyze growth and requirements
Rapid data growth needs spreading data and fast access with backups.Step 2: Match techniques to needs
Horizontal scaling adds servers; sharding splits data; replication copies data for speed and fault tolerance.Step 3: Evaluate other options
Vertical scaling alone can't handle rapid growth well; replication alone doesn't split data; deleting data loses information.Final Answer:
Horizontal scaling with sharding and replication -> Option CQuick Check:
Sharding + replication = scalable and reliable [OK]
- Relying only on vertical scaling for big growth
- Using replication without sharding for large data
- Deleting data instead of scaling
Ready to prove it?
Pass the test and this pattern moves unknown
