The Single Responsibility Principle at Service Level
What you'll learn: How to apply the Single Responsibility Principle (SRP) to microservices so each service has exactly one reason to change.
The Core Idea
You've seen SRP applied to classes and modules—a component should have only one reason to change. At the service level, this means each microservice should own a cohesive set of capabilities focused on one business responsibility. When business requirements change in a specific area, ideally only one service should need modification.
Why SRP Matters for Services
Imagine a monolithic "CustomerService" that handles customer profiles, authentication, order history, and email preferences. When the email system needs upgrading, you're deploying a service that also touches authentication logic. That's risky.
Instead, separate services:
- CustomerProfileService - manages customer data
- AuthenticationService - handles login and tokens
- NotificationPreferencesService - manages email/SMS settings
Now, changing notification logic doesn't risk breaking authentication. Each service has one reason to change.
Practical Application
When defining service boundaries by business capabilities (as you learned in lesson 1304), ask:
- What single business capability does this service own?
- If requirement X changes, which services must change? (Ideally just one)
- Can I explain this service's responsibility in one sentence without using "and"?
A well-designed service boundary means changes stay localized. This reduces deployment risk, enables independent scaling, and allows teams to work autonomously.
Avoiding the Trap
Don't confuse "single responsibility" with "single function." A service can have multiple operations (create, read, update, delete) as long as they're all cohesive around one business concept.
Key Takeaway: Each microservice should have one reason to change—aligning services with distinct business capabilities ensures changes remain isolated and systems stay maintainable at scale.