Bird
Raised Fist0
Microservicessystem_design~10 mins

Single responsibility per service in Microservices - Scalability & System Analysis

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Scalability Analysis - Single responsibility per service
Growth Table: Single Responsibility per Service
UsersWhat Changes?
100 usersFew services, simple communication, low traffic per service
10,000 usersMore services added, service communication increases, need for service discovery
1,000,000 usersMany services, complex dependencies, need for load balancing and fault tolerance
100,000,000 usersMassive service mesh, automated scaling, advanced monitoring, and orchestration
First Bottleneck

The first bottleneck is usually the communication overhead between many small services. As each service has a single responsibility, the number of calls between services grows quickly, increasing latency and network load.

Scaling Solutions
  • Service Mesh: Use a service mesh to manage communication, retries, and load balancing efficiently.
  • API Gateway: Aggregate calls to reduce chattiness between services.
  • Horizontal Scaling: Add more instances of each service behind load balancers.
  • Caching: Cache frequent responses to reduce inter-service calls.
  • Asynchronous Messaging: Use message queues to decouple services and reduce synchronous calls.
  • Monitoring & Tracing: Implement distributed tracing to identify slow calls and optimize.
Back-of-Envelope Cost Analysis

Assuming 1 million users generate 10,000 requests per second total:

  • Total requests per second: ~10,000
  • Each request may call 3-5 services → 30,000-50,000 inter-service calls per second
  • Network bandwidth depends on payload size; assume 10KB per call → 300-500 MB/s network traffic
  • Storage depends on service data; each service stores its own data, so total storage grows with number of services and data retention
Interview Tip

Start by explaining the benefits of single responsibility per service: easier maintenance, independent deployment, and clear ownership. Then discuss how this leads to increased communication overhead as scale grows. Finally, describe concrete solutions like service mesh, caching, and asynchronous messaging to handle scaling challenges.

Self Check

Your database handles 1000 QPS. Traffic grows 10x. What do you do first?

Answer: Introduce read replicas and caching layers to reduce load on the primary database before scaling application servers or sharding data.

Key Result
Single responsibility per service improves modularity but increases inter-service communication, which becomes the first bottleneck as user scale grows; solutions focus on managing communication efficiently through service mesh, caching, and asynchronous messaging.

Practice

(1/5)
1. What does the single responsibility principle mean in microservices?
easy
A. Services should be tightly coupled to improve performance.
B. Each service should handle multiple unrelated tasks.
C. Services should share the same database for all tasks.
D. Each service should do only one specific job.

Solution

  1. Step 1: Understand the principle meaning

    Single responsibility means one service focuses on one task or job only.
  2. Step 2: Evaluate options against this meaning

    Each service should do only one specific job. matches the principle exactly; others contradict it by mixing tasks or coupling.
  3. Final Answer:

    Each service should do only one specific job. -> Option D
  4. Quick Check:

    Single responsibility = One job per service [OK]
Hint: One service, one job keeps design simple and clear [OK]
Common Mistakes:
  • Thinking one service can do many unrelated tasks
  • Assuming shared databases mean single responsibility
  • Confusing tight coupling with single responsibility
2. Which of the following is the correct way to name a microservice following single responsibility?
easy
A. UserManagementService
B. UserAndOrderService
C. Service123
D. DatabaseService

Solution

  1. Step 1: Identify naming that reflects single responsibility

    The service name should clearly indicate one focused responsibility.
  2. Step 2: Check options for clarity and focus

    UserManagementService clearly states it manages users only; others mix concerns or are vague.
  3. Final Answer:

    UserManagementService -> Option A
  4. Quick Check:

    Clear, focused name = single responsibility [OK]
Hint: Service name should reflect one clear job [OK]
Common Mistakes:
  • Using vague or numeric names without meaning
  • Combining multiple domains in one service name
  • Naming services after infrastructure components
3. Given these microservices: UserService handles user data, OrderService handles orders. Which service should handle payment processing?
medium
A. UserService
B. PaymentService
C. OrderService
D. DatabaseService

Solution

  1. Step 1: Analyze responsibilities of existing services

    UserService manages users, OrderService manages orders, so payment is a separate concern.
  2. Step 2: Assign payment to a dedicated service

    Payment processing is a distinct responsibility, so PaymentService is appropriate.
  3. Final Answer:

    PaymentService -> Option B
  4. Quick Check:

    Separate payment = separate service [OK]
Hint: Separate distinct jobs into separate services [OK]
Common Mistakes:
  • Assigning payment to unrelated services
  • Combining payment with user or order logic
  • Using generic service names that mix concerns
4. You find a microservice called InventoryAndShippingService causing deployment issues. What is the best fix following single responsibility?
medium
A. Merge it with UserService to reduce services
B. Add more features to InventoryAndShippingService
C. Split it into two services: InventoryService and ShippingService
D. Keep it as is and increase server resources

Solution

  1. Step 1: Identify problem with combined responsibilities

    Inventory and shipping are two distinct jobs combined, causing complexity and deployment issues.
  2. Step 2: Apply single responsibility by splitting services

    Splitting into InventoryService and ShippingService isolates concerns and simplifies management.
  3. Final Answer:

    Split it into two services: InventoryService and ShippingService -> Option C
  4. Quick Check:

    Split combined services to fix issues [OK]
Hint: Split combined services to fix complexity [OK]
Common Mistakes:
  • Merging unrelated services increases complexity
  • Adding features to overloaded services worsens problems
  • Ignoring root cause and just adding resources
5. You are designing a microservices system for an online store. Which design best follows single responsibility per service?
hard
A. UserService, ProductService, OrderService, PaymentService, NotificationService
B. StoreService handling users, products, orders, payments, and notifications
C. UserService and OrderService only, handling all tasks
D. One big service for all store functions

Solution

  1. Step 1: Understand the scope of each option

    UserService, ProductService, OrderService, PaymentService, NotificationService splits store functions into focused services; others combine many tasks.
  2. Step 2: Match design to single responsibility principle

    UserService, ProductService, OrderService, PaymentService, NotificationService clearly assigns one responsibility per service, making it scalable and maintainable.
  3. Final Answer:

    UserService, ProductService, OrderService, PaymentService, NotificationService -> Option A
  4. Quick Check:

    One service, one job = UserService, ProductService, OrderService, PaymentService, NotificationService [OK]
Hint: Split big tasks into small focused services [OK]
Common Mistakes:
  • Combining many tasks into one service
  • Using too few services for complex domains
  • Ignoring scalability and maintainability