| Users | Data Management | Service Independence | Data Conflicts | Scaling Complexity |
|---|---|---|---|---|
| 100 users | Single shared database possible | Low, services tightly coupled | Minimal conflicts | Simple scaling |
| 10,000 users | Services start owning own databases | Moderate independence, some duplication | Conflicts start appearing | Moderate complexity |
| 1,000,000 users | Each service owns its data fully | High independence, clear boundaries | Conflicts minimized by design | High complexity, requires automation |
| 100,000,000 users | Data ownership critical for scaling | Complete autonomy, polyglot persistence | Conflicts handled asynchronously | Very high complexity, advanced tooling |
Why each service owns its data in Microservices - Scalability Evidence
Start learning this pattern below
Jump into concepts and practice - no test required
When multiple services share the same database, the database becomes the first bottleneck as user count grows. This causes tight coupling, making it hard to scale services independently. Data conflicts and schema changes affect all services, slowing development and deployment.
- Database per service: Each service manages its own database to isolate data and reduce coupling.
- API contracts: Services communicate via APIs, not shared databases, ensuring clear boundaries.
- Event-driven data sync: Use events to synchronize data asynchronously between services.
- Polyglot persistence: Services choose the best database type for their data needs.
- Automated deployment: Independent data ownership enables independent service deployment and scaling.
Assuming 1 million users with 10 requests per user per day:
- Requests per second: ~115 (1,000,000 users * 10 requests / 86400 seconds)
- Database load per service: Reduced by isolating data, each handles only relevant queries.
- Storage: Distributed across services, allowing tailored storage solutions.
- Network bandwidth: Increased inter-service communication but manageable with efficient APIs.
Start by explaining the problem of shared databases causing coupling and bottlenecks. Then describe how owning data per service improves independence and scalability. Discuss trade-offs like data duplication and eventual consistency. Finally, mention practical solutions like event-driven sync and polyglot persistence.
Your database handles 1000 QPS. Traffic grows 10x. What do you do first?
Answer: Split the shared database into multiple databases owned by individual services to reduce coupling and distribute load, enabling independent scaling.
Practice
Solution
Step 1: Understand service independence
Each microservice owning its data means it can change its database without affecting others.Step 2: Recognize benefits of separate data ownership
This independence improves scalability and reduces tight coupling between services.Final Answer:
To ensure services are independent and can evolve separately -> Option AQuick Check:
Service independence = D [OK]
- Assuming shared databases improve performance
- Believing data sharing reduces storage needs
- Thinking SQL queries are easier with shared data
Solution
Step 1: Identify proper data access method
Microservices should not access each other's databases directly to avoid tight coupling.Step 2: Recognize communication via APIs or messages
Services communicate data through APIs or messaging systems to maintain independence.Final Answer:
Using APIs or messaging to request data -> Option CQuick Check:
Data access via APIs/messages = B [OK]
- Trying to query another service's database directly
- Assuming shared schema is best practice
- Copying entire databases unnecessarily
Solution
Step 1: Identify correct data access respecting ownership
Service B should not access Service A's database directly or share databases.Step 2: Use API calls for data retrieval
Calling Service A's API allows Service B to get needed data without breaking ownership rules.Final Answer:
Service B calls Service A's API to get customer info -> Option BQuick Check:
API calls respect ownership = A [OK]
- Direct DB queries across services
- Duplicating data causing inconsistency
- Using shared databases breaking independence
Solution
Step 1: Analyze impact of shared database schema
Sharing schema and direct queries create tight coupling between services.Step 2: Understand consequences on independence
Tight coupling reduces the ability to change or scale services independently.Final Answer:
It causes tight coupling and reduces service independence -> Option AQuick Check:
Tight coupling problem = C [OK]
- Thinking shared DB improves scalability
- Assuming it simplifies API design
- Believing it removes sync needs
Solution
Step 1: Respect data ownership in design
Each service must own and manage its own data; direct DB queries or shared DB break this.Step 2: Use API calls for inter-service communication
Order service should call Inventory service's API to get real-time stock info, ensuring data consistency and independence.Final Answer:
Order service calls Inventory service's API to check stock availability -> Option DQuick Check:
API communication respects ownership = A [OK]
- Direct DB queries breaking independence
- Duplicating data causing stale info
- Using shared DB increasing coupling
