Course contentsShow
← System Design
Lesson 816 of 1,91921. Microservices ArchitectureFree lesson

Single Responsibility at Service Level

Applying single responsibility principle to define cohesive services with clear, focused purposes.

Single Responsibility at Service Level

What you'll learn: How to apply the single responsibility principle to design microservices that each do one thing well.

The Core Idea

Just as a class should have one reason to change, a microservice should have one clear business capability or domain concern. Each service should own a specific, well-defined piece of functionality and do it completely—without depending on other services to fulfill its core purpose.

What This Looks Like in Practice

A Payment Service should handle payment processing, transaction records, and refunds. It shouldn't also manage user profiles, send marketing emails, or track inventory. Those are different responsibilities that belong elsewhere.

Think of services like specialists in a hospital: the cardiologist focuses on hearts, the radiologist on imaging, and the pharmacist on medications. Each has a clear, focused role. You wouldn't ask the cardiologist to also dispense medications—that creates confusion and dependencies.

Applying the Principle

When defining a service boundary, ask:

  • What single business capability does this serve? (e.g., "handle orders," "manage inventory")
  • Who owns this data and logic? (one team, one responsibility)
  • Would this service change if multiple unrelated business concerns changed? (if yes, it's doing too much)

Services with single responsibility are easier to understand, test, deploy independently, and scale. They align with bounded contexts from domain-driven design—each service models one cohesive part of your business domain.

Anti-Pattern: The "God Service"

A service that handles users, orders, payments, notifications, and analytics has multiple reasons to change. Every business concern creates coupling, making the service fragile and hard to evolve.

Key Takeaway: Define each microservice around one clear business capability—it should have a single, focused purpose that can be understood and owned independently.