Bird
Raised Fist0
Microservicessystem_design~20 mins

Single responsibility per service in Microservices - Practice Problems & Coding Challenges

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
Challenge - 5 Problems
🎖️
Single Responsibility Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why is single responsibility important in microservices?

Imagine you have a microservice that handles both user authentication and payment processing. What is the main risk of combining these responsibilities in one service?

AIt increases the chance of bugs affecting unrelated features and complicates scaling.
BIt makes the service easier to maintain and scale independently.
CIt reduces network latency between authentication and payment functions.
DIt allows the service to use fewer resources by sharing code.
Attempts:
2 left
💡 Hint

Think about how mixing different tasks can affect updates and failures.

Architecture
intermediate
2:00remaining
Identifying single responsibility in service design

You are designing a microservice for an online bookstore. Which service design best follows the single responsibility principle?

AA single service that handles all business logic and database access.
BSeparate services: one for user accounts, one for orders, and one for inventory management.
COne service for user accounts and orders, another for inventory and shipping.
DA service that manages user accounts, orders, and inventory all together.
Attempts:
2 left
💡 Hint

Think about dividing responsibilities so each service does one main job.

scaling
advanced
2:00remaining
Scaling microservices with single responsibility

You have two microservices: Service A handles user profiles, and Service B handles payment processing. Service B experiences high load during sales. What is the best scaling approach?

AScale both Service A and Service B equally to handle the load.
BMerge Service A and B to share resources and scale together.
CScale Service A only because user profiles are critical.
DScale only Service B independently since it has high load.
Attempts:
2 left
💡 Hint

Consider which service is under stress and how single responsibility helps.

tradeoff
advanced
2:00remaining
Tradeoffs of strict single responsibility in microservices

What is a potential downside of applying single responsibility too strictly by creating many tiny microservices?

AIt can increase communication overhead and operational complexity.
BIt simplifies deployment and reduces network calls.
CIt eliminates the need for service discovery and load balancing.
DIt reduces fault isolation and makes debugging harder.
Attempts:
2 left
💡 Hint

Think about what happens when many small services need to talk to each other.

component
expert
3:00remaining
Designing a microservice with single responsibility

You need to design a microservice responsible only for sending email notifications. Which components should this service include to follow single responsibility best?

AEmail sending logic, payment processing, and user authentication.
BUser management, email template storage, and email sending logic.
CEmail sending logic, email template storage, and retry mechanism for failed emails.
DEmail sending logic and order processing.
Attempts:
2 left
💡 Hint

Focus on components directly related to sending emails.

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