| Users/Scale | 100 Users | 10K Users | 1M Users | 100M Users |
|---|---|---|---|---|
| Service Count | Few (3-5) | 10-20 | 50-100 | Hundreds+ |
| Service Size | Small, focused | Small, focused | Small, focused | Small, focused |
| Inter-service Calls | Low | Moderate | High | Very High |
| Data Ownership | Clear per service | Clear per service | Clear per service | Clear per service |
| Deployment Frequency | Low | Moderate | High | Very High |
| Complexity | Low | Moderate | High | Very High |
High cohesion in Microservices - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
At small scale, the first bottleneck is usually the database because each microservice owns its data and queries increase with users.
As users grow, inter-service communication becomes the bottleneck due to many small services calling each other, causing latency and network overhead.
Without high cohesion, services may have overlapping responsibilities, increasing coupling and making scaling harder.
- Maintain small, focused services: Each service handles a single responsibility to reduce complexity and improve scalability.
- Database per service: Avoid shared databases to reduce contention and allow independent scaling.
- Use asynchronous communication: Message queues or event-driven patterns reduce tight coupling and improve resilience.
- API Gateway and service mesh: Manage inter-service calls efficiently and monitor traffic.
- Horizontal scaling: Add more instances of services independently based on load.
- Cache frequently accessed data: Reduce database load and improve response times.
- Automate deployments: Continuous integration and delivery help manage many small services.
Assuming 1M users generating 100 requests per second (RPS) total:
- Each microservice handles ~100-1000 RPS depending on responsibility.
- Database instances per service handle ~5000 QPS; scaling needed if exceeded.
- Network bandwidth depends on payload size; 1 Gbps (~125 MB/s) supports many small calls.
- Storage grows with data owned by each service; archiving old data reduces cost.
When discussing high cohesion in microservices, start by explaining the importance of single responsibility per service.
Describe how this reduces complexity and improves scalability.
Then, discuss bottlenecks like database load and inter-service communication.
Finally, explain scaling solutions like asynchronous messaging, caching, and horizontal scaling.
Your database handles 1000 QPS. Traffic grows 10x. What do you do first?
Answer: Add read replicas and implement caching to reduce database load before scaling vertically or sharding.
Practice
high cohesion mean in microservices architecture?Solution
Step 1: Understand the meaning of cohesion
Cohesion means how closely related the tasks inside a module or service are.Step 2: Apply cohesion to microservices
High cohesion means grouping related tasks in one service to keep it focused and manageable.Final Answer:
Grouping related tasks and responsibilities within a single service -> Option DQuick Check:
High cohesion = grouping related tasks [OK]
- Thinking high cohesion means splitting every function separately
- Confusing cohesion with coupling
- Believing unrelated tasks should be combined
- Assuming database design defines cohesion
Solution
Step 1: Identify related tasks in options
A service that manages all user-related operations like profile, login, and preferences groups user-related operations which are closely related.Step 2: Check other options for unrelated tasks
Options A and B mix unrelated tasks; D lacks business logic, so not cohesive.Final Answer:
A service that manages all user-related operations like profile, login, and preferences -> Option AQuick Check:
High cohesion = related user tasks together [OK]
- Choosing options that mix unrelated responsibilities
- Ignoring business logic in cohesion
- Confusing data storage with service responsibility
- Assuming more tasks always mean better cohesion
OrderService handles order creation, payment processing, and shipping updates. What is the likely issue with this design regarding high cohesion?Solution
Step 1: Analyze the tasks in OrderService
Order creation, payment, and shipping are different domains with distinct logic.Step 2: Evaluate cohesion
Mixing payment and shipping with order creation lowers cohesion because responsibilities differ.Final Answer:
The service has low cohesion because it mixes unrelated responsibilities -> Option AQuick Check:
Mixed tasks = low cohesion [OK]
- Assuming all order-related tasks are always cohesive
- Confusing scalability with cohesion
- Ignoring domain boundaries
- Believing loosely coupled means high cohesion
InventoryService currently manages stock levels and supplier payments. What is the best fix to improve high cohesion?Solution
Step 1: Identify unrelated responsibilities
Supplier payments are unrelated to stock level management.Step 2: Suggest separation for high cohesion
Moving payments to a dedicated PaymentService improves cohesion by grouping related tasks.Final Answer:
Split supplier payments into a separate PaymentService -> Option CQuick Check:
Separate unrelated tasks to improve cohesion [OK]
- Adding unrelated tasks to the same service
- Combining unrelated services
- Ignoring cohesion for simplicity
- Confusing cohesion with coupling
Solution
Step 1: Evaluate grouping of related tasks
UserService (user profiles, authentication), OrderService (orders, payments), ShippingService (shipping updates, tracking) groups related tasks logically by domain, supporting high cohesion.Step 2: Compare with other options
UserService (user profiles, payments), OrderService (orders, shipping), InventoryService (stock levels, payments) mixes payments in unrelated services; C is a monolith; D over-splits causing low cohesion.Final Answer:
UserService (user profiles, authentication), OrderService (orders, payments), ShippingService (shipping updates, tracking) -> Option BQuick Check:
Group related domain tasks for high cohesion [OK]
- Mixing unrelated tasks in one service
- Creating too many tiny services
- Building monolithic services
- Ignoring domain boundaries
