| Users / Traffic | Database Behavior | Architecture Impact |
|---|---|---|
| 100 users | Single instance DB handles requests easily | Simple architecture, direct DB connection |
| 10,000 users | DB load increases, latency may rise | Introduce connection pooling, caching layers |
| 1 million users | Single DB instance bottleneck; scaling limits reached | Need read replicas, sharding, or NoSQL options |
| 100 million users | Massive data volume and traffic; complex queries slow | Distributed DB clusters, multi-region replication, polyglot persistence |
Why database choice impacts architecture in HLD - Scalability Evidence
The database is usually the first component to break as user count and data grow. This happens because databases have limits on how many queries they can process per second and how much data they can store efficiently. When the DB is overwhelmed, response times increase and the whole system slows down.
- Vertical Scaling: Upgrade to more powerful servers with faster CPUs, more RAM, and SSD storage.
- Read Replicas: Create copies of the database to handle read queries, reducing load on the main DB.
- Sharding: Split data horizontally across multiple database servers to distribute load.
- Caching: Use in-memory caches like Redis or Memcached to serve frequent queries quickly.
- NoSQL Databases: Use databases optimized for specific data types or access patterns (e.g., document stores, key-value stores) for better scalability.
- Polyglot Persistence: Combine multiple database types to handle different parts of data efficiently.
- At 1 million users, assuming 10 requests per user per day, total requests = 10 million/day ≈ 115 requests/sec.
- A single PostgreSQL instance can handle ~5,000 QPS, so DB can handle this load but with little room for growth.
- Storage needs grow with data size; 100 million users may require terabytes of storage.
- Network bandwidth must support data transfer; 1 Gbps network can handle ~125 MB/s, enough for many applications but may need upgrades at large scale.
Start by identifying the database's role and limits in your system. Discuss expected traffic and data growth. Explain how the database choice affects read/write patterns, consistency, and latency. Then describe bottlenecks and propose scaling solutions like replication, sharding, or caching. Finally, mention trade-offs and cost implications.
Your database handles 1000 queries per second (QPS). Traffic grows 10x to 10,000 QPS. What do you do first and why?
Practice
Solution
Step 1: Understand database roles in architecture
Databases store and manage data, affecting how data is accessed and maintained.Step 2: Recognize differences in consistency and scaling
Relational and NoSQL databases differ in consistency guarantees and how they scale horizontally or vertically.Final Answer:
Different databases handle data consistency and scaling differently -> Option DQuick Check:
Database choice affects consistency and scaling [OK]
- Assuming all databases behave the same
- Ignoring scaling differences
- Thinking database choice doesn't affect performance
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100));?Solution
Step 1: Identify the syntax style
TheCREATE TABLEstatement with columns and types is standard SQL syntax.Step 2: Match syntax to database type
Relational databases use SQL and tables with defined schemas.Final Answer:
Relational SQL database -> Option CQuick Check:
SQL table creation = Relational database [OK]
- Confusing NoSQL with SQL syntax
- Assuming all databases use SQL
- Ignoring schema definitions
Solution
Step 1: Understand NoSQL document database traits
NoSQL document stores often allow flexible schemas and scale horizontally.Step 2: Identify scaling and consistency trade-offs
They usually provide eventual consistency and support sharding for horizontal scaling.Final Answer:
Easier horizontal scaling with eventual consistency -> Option AQuick Check:
NoSQL scaling = horizontal + eventual consistency [OK]
- Expecting strong ACID transactions in NoSQL
- Assuming rigid schemas
- Thinking sharding is limited
Solution
Step 1: Analyze the problem context
Relational databases can struggle with very high write loads due to ACID constraints.Step 2: Identify architectural mistake
Ignoring NoSQL databases that handle high write throughput with eventual consistency is a common error.Final Answer:
Ignoring NoSQL options that scale writes better -> Option BQuick Check:
High write load needs scalable DB choice [OK]
- Assuming relational DB always best
- Confusing consistency models
- Misusing key-value stores for complex queries
Solution
Step 1: Analyze requirements
The system needs fast reads, flexible data, and can tolerate eventual consistency.Step 2: Match database features to needs
NoSQL document databases provide flexible schemas, scale horizontally worldwide, and support eventual consistency.Step 3: Evaluate other options
Relational DBs have strong consistency but less flexible scaling; in-memory stores lack persistence; graph DBs may not scale globally easily.Final Answer:
NoSQL document database for flexible schema and horizontal scaling -> Option AQuick Check:
Global scale + flexible data = NoSQL document DB [OK]
- Choosing relational DB despite scaling limits
- Using in-memory store without persistence
- Ignoring horizontal scaling needs
Ready to prove it?
Pass the test and this pattern moves unknown
