Size and Scope Guidelines
What you'll learn: How to determine the right size for a microservice by focusing on business capabilities instead of counting lines of code.
The Business Capability Approach
When designing microservices, the question "How big should a service be?" tempts many teams to use arbitrary metrics like "no more than 1000 lines of code" or "must fit in one developer's head." These rules miss the point entirely.
Size microservices around business capabilities, not code metrics.
A business capability is a what the business does—like "process payments," "manage inventory," or "handle user authentication." Each represents a cohesive piece of business logic that changes together for the same reasons.
Why Code Size Doesn't Matter
Imagine two services:
- Service A: 500 lines managing the entire order lifecycle (placement, modification, fulfillment, cancellation)
- Service B: 2000 lines handling payment processing with fraud detection, multiple payment gateways, and reconciliation
Service A is smaller in code but does too much—it mixes multiple business capabilities. Service B is larger but focused on one capability. Service B is better scoped.
The Right Questions
Ask yourself:
- Does this service own one clear business capability?
- Could a single team understand and own it completely?
- Does it have a well-defined boundary that rarely needs to change when other capabilities change?
- Can it be deployed independently without coordinating with other services?
A "small" service that spans multiple business contexts creates coupling. A "large" service focused on one capability maintains independence.
Key Takeaway: Size your microservices by business capability boundaries, not lines of code—a well-scoped service might be large if the capability is complex, or small if the capability is simple.