Clean code
  • Overview
    • Introduction
    • Why is clean code so important?
    • What Is Clean Code?
    • How to write clean code?
    • Conventions
  • The key principles of clean code
    • Meaningful Names
    • Functions
    • Classes
    • Comments
    • Error Handling
      • Exception handling best practices
    • Unit Tests
    • Formatting
    • Objects and Data Structures
    • Simple Design Rules
    • Concurrency
    • Code Smells
  • Building Maintainable Software
    • Write Short Units of Code
    • Write Simple Units of Code
    • Write Code Once
    • Keep Unit Interfaces Small
    • Write Clean Code
    • Automate Tests
  • Bonus
    • SOLID Principle
      • SRP - Single Responsibility Principle
      • OCP - Open-Closed Principle
      • LSP - Liskov Substitution Principle
      • ISP - Interface Segregation Principle
      • DIP - Dependency Inversion Principle
    • LoD Principle
    • YAGNI Principle
    • DRY Principle
    • Fail Fast principle
    • Hollywood Principle
    • Library vs Framework
    • Coupling and Cohesion
    • AOP - Aspect-Oriented Programming
      • Building an AOP framework
    • OOP Design Pattern
    • Technical Dept
    • How to learn software Design and Architecture - Roadmap
    • Microservcies
      • Defining the scope of a microservice
      • Step-by-Step: How to Identify Over-Scoped Microservices
      • Benefits of Grouping or Consolidating Microservices
      • A practical step-by-step plan to consolidate microservice
Powered by GitBook
On this page
  1. Bonus
  2. Microservcies

Defining the scope of a microservice

Defining the scope of a microservice is a critical step when designing a microservice architecture. A well-defined scope ensures that each microservice is:

  • Small and manageable

  • Loosely coupled with other services

  • Highly cohesive (does one thing well)

  • Independently deployable

Here's a practical guide to help you define the scope:


🔍 1. Start with the Business Domain (Domain-Driven Design - DDD)

Use DDD concepts to break down your application into bounded contexts. A bounded context represents a logical boundary where a particular domain model is defined and applicable.

Example:

  • For an e-commerce app, you might have:

    • User Management

    • Product Catalog

    • Order Management

    • Payment

    • Shipping

Each of these could become a separate microservice.


🎯 2. Single Responsibility Principle

Each microservice should do one thing and do it well. Avoid mixing concerns like authentication with order processing, for instance.


🔗 3. Identify Service Boundaries

Consider:

  • Ownership of data: Each service should own its own database.

  • API contracts: Define clear input/output.

  • Minimal dependencies: Avoid tight coupling with other services.


🧱 4. Think in Terms of Capabilities

Define services by capabilities rather than technical layers (e.g., avoid "UserRepositoryService"). Instead, go for "UserProfileService" or "OrderService" that handle business capabilities.


📈 5. Autonomy and Scalability

Ask:

  • Can this service be developed and deployed independently?

  • Will it need to scale separately?


⚖️ 6. Right Size It

Avoid over-engineering with too many tiny services (nano-services). A good rule of thumb: if your service logic can be owned by one small team and released independently, it's likely scoped right.


🧩 7. Define Inputs/Outputs (APIs)

Clarify:

  • What data the service needs

  • What data it provides

  • What events it listens to or emits (if event-driven)


✅ 8. Validation Checklist

Ask these questions:

  • Does the service align with a business function?

  • Can it be independently developed, deployed, and scaled?

  • Does it own its data?

  • Is the service boundary clear?

PreviousMicroservciesNextStep-by-Step: How to Identify Over-Scoped Microservices

Last updated 1 day ago