| Users | Data Volume | Database Setup | Challenges | Changes Needed |
|---|---|---|---|---|
| 100 users | Small (MBs) | Single monolithic database | Simple queries, low latency | None, simple design works |
| 10,000 users | Medium (GBs) | Monolithic DB with read replicas | Read scaling, some write contention | Add read replicas, caching |
| 1,000,000 users | Large (TBs) | Decompose DB by service (microservices) | Write bottlenecks, complex joins, latency | Split DB by domain, use separate DB per microservice |
| 100,000,000 users | Very Large (PBs) | Sharded and decomposed DBs per service | Cross-service data consistency, network latency | Shard databases, async communication, event sourcing |
Database decomposition strategy in Microservices - Scalability & System Analysis
At around 1 million users, the monolithic database becomes the first bottleneck. It struggles with write throughput and complex joins across large tables. This causes slow response times and limits scaling.
- Database decomposition: Split the monolithic database into multiple smaller databases aligned with microservices. Each service owns its data.
- Horizontal scaling: Add more database instances for each microservice to distribute load.
- Caching: Use caches to reduce database reads for frequently accessed data.
- Sharding: Partition large databases by key ranges or user IDs to spread data across servers.
- Async communication: Use event-driven patterns to sync data between services without blocking.
- At 1M users, expect ~10,000 QPS (queries per second) on the database.
- A single PostgreSQL instance handles ~5,000 QPS, so two or more DBs needed.
- Storage grows to terabytes; decomposed DBs reduce single DB size.
- Network bandwidth increases due to inter-service communication; plan for 1 Gbps+ links.
- Caching reduces DB load by 30-50%, saving costs and improving latency.
Start by explaining the limits of a monolithic database as users grow. Then describe how splitting data by service boundaries helps scale. Discuss trade-offs like data consistency and complexity. Finally, mention caching, sharding, and async communication as further steps.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add read replicas and implement caching to reduce load on the primary database before considering decomposition or sharding.
Practice
vertical decomposition in database design for microservices?Solution
Step 1: Understand vertical decomposition
Vertical decomposition means splitting a database by grouping related tables or columns, often by business capability or domain.Step 2: Compare with other options
Horizontal decomposition splits by rows, geographic is location-based, and combining is the opposite of decomposition.Final Answer:
Splitting a database by grouping related tables or columns into separate databases -> Option DQuick Check:
Vertical decomposition = splitting by columns/tables [OK]
- Confusing vertical with horizontal decomposition
- Thinking vertical means geographic split
- Assuming decomposition means combining databases
horizontal decomposition in microservices database design?Solution
Step 1: Define horizontal decomposition
Horizontal decomposition splits data by rows, for example, dividing customers by region or user ID ranges.Step 2: Eliminate incorrect options
Splitting data by columns or tables based on functionality describes vertical decomposition, C is merging (not decomposition), and D is about engines, not decomposition strategy.Final Answer:
Dividing data by rows, such as by customer or region -> Option AQuick Check:
Horizontal decomposition = split by rows [OK]
- Mixing horizontal with vertical decomposition
- Thinking horizontal means merging databases
- Confusing database engine separation with decomposition
Solution
Step 1: Understand horizontal decomposition by region
Horizontal decomposition splits data by rows, so each shard holds users from a specific region.Step 2: Identify which shard to query
Querying European users targets only the shard holding European data, not others.Final Answer:
Only the database shard containing European users -> Option AQuick Check:
Query targets relevant shard only [OK]
- Querying all shards unnecessarily
- Querying wrong region shard
- Assuming data is merged in one database
Solution
Step 1: Identify problem with vertical decomposition
Vertical decomposition splits by tables/domains, but if services need to join data often, it causes latency.Step 2: Recommend fix
Redesign to reduce cross-service joins by better domain boundaries or data duplication to avoid latency.Final Answer:
Poor vertical decomposition causing cross-service joins; Fix: Redesign to reduce cross-service dependencies -> Option CQuick Check:
Cross-service joins cause latency; fix by better decomposition [OK]
- Confusing horizontal with vertical decomposition issues
- Thinking merging databases fixes latency
- Blaming database type instead of design
Solution
Step 1: Understand combined vertical and horizontal decomposition
Data is split horizontally by country and vertically by data type (profile, orders), so data is in different shards and databases.Step 2: Choose best query approach
Cross-database joins are expensive and complex; merging data loses benefits. API composition aggregates data from services after querying relevant shards efficiently.Final Answer:
Use API composition to aggregate data from profile and order services after querying country-specific shards -> Option BQuick Check:
API composition handles multi-db queries efficiently [OK]
- Trying cross-database joins causing latency
- Merging databases losing scalability
- Ignoring decomposition benefits for simplicity
Ready to prove it?
Pass the test and this pattern moves unknown
