Microservices

Independent services organized by domain, responsible for business logic, persistence, and the system's core events.

What is a microservice in this architecture?

A microservice is a functional unit responsible for a specific domain or bounded context.

For example:

  • users
  • products
  • orders
  • payments
  • inventory
  • notifications

Each service should have a clear purpose and understandable boundaries.

What lives inside a microservice

API Layer

Exposes endpoints or input interfaces.

Application Layer

Orchestrates use cases.

Domain Layer

Contains rules, entities, value objects, and the core domain logic.

Infrastructure Layer

Connects to databases, queues, external clients, and technical details.

Core responsibilities

  • Implement business rules
  • Validate domain invariants
  • Persist data
  • Publish relevant events
  • Maintain clear contracts

Database per service

A common practice is for each microservice to have control over its own persistence.

This helps to:

  • reduce coupling
  • protect the domain
  • avoid direct dependency between services

Sharing a single database across many services tends to lead to coupling that is hard to govern.

Benefits

  • Clearer boundaries per domain
  • Independent deployments
  • Decoupled evolution
  • More well-defined team ownership

Risks

  • Services that are too small without a clear reason
  • Too much synchronous communication between services
  • Poorly defined contracts
  • Distributed consistency handled badly
  • Weak governance

How do they connect?

Microservices can connect:

  • synchronously, through APIs
  • asynchronously, through events

In general:

  • use synchronous communication when an immediate response is needed
  • use asynchronous communication when you want temporal decoupling

Practical example

ms-orders can:

  • receive a request to create an order
  • validate domain rules
  • persist the order
  • publish OrderPlaced

Other services then react to that event according to their responsibility.

Summary

Microservices are the functional core of the architecture. Their value lies in separating the domain into clear boundaries, not in fragmenting the system arbitrarily.