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
  • 🧩 What to Merge vs What to Keep
  • 🔄 Example
  • 🔧 Tooling Tips
  1. Bonus
  2. Microservcies

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

1. Map Your Current Microservices

Create a visual or list-based map of:

  • All microservices

  • Their responsibilities

  • Their data ownership

  • Their API contracts

  • Inter-service communications (REST, events, etc.)

This will help you see overlaps and redundancies.


2. Spot the Smells (Signs of Too Many Microservices)

Look for services that:

  • Only wrap a database table (CRUD-only services)

  • Are tightly coupled to others (e.g. always deployed together)

  • Communicate too frequently (chatty services)

  • Have no real domain meaning (e.g., NotificationDbService)

  • Are owned by the same team and change together

These are candidates for consolidation.


3. Group by Business Capability

Re-cluster services by business capabilities rather than technical responsibilities.

Example:

  • UserProfileService, UserSettingsService, and UserNotificationPreferencesService might be better off as one UserAccountService.


4. Review Service Interactions

If two services:

  • Call each other frequently

  • Share data models

  • Are part of the same user flow (e.g. CartService + CartPricingService)

They probably shouldn't be separate unless there's a good scaling or ownership reason.


5. Review Teams & Deployment

Ask:

  • Are multiple services always deployed together?

  • Are they maintained by the same team?

  • Do they require coordination on every change?

If yes, consider merging them.


6. Check for DDD Violations

If your services don’t align with business boundaries or bounded contexts, you're likely over-segmented.


🧩 What to Merge vs What to Keep

Criteria
Merge
Keep Separate

Always deployed together

✅

❌

Same bounded context

✅

❌

High communication

✅

❌

Distinct business logic

❌

✅

Different scaling requirements

❌

✅

Owned by different teams

❌

✅


🔄 Example

Let’s say you have:

  • EmailService

  • SMSService

  • PushNotificationService

You could consolidate them into a single NotificationService with strategy pattern or plugins to handle different channels.


🔧 Tooling Tips

  • Use tools like Kiali, Zipkin, or Jaeger if you’re on a service mesh (Istio) to visualize service traffic and dependencies.

  • For static analysis: build service dependency graphs based on your codebase or OpenAPI specs.

PreviousDefining the scope of a microserviceNextBenefits of Grouping or Consolidating Microservices

Last updated 1 day ago