Microservices

Microservices split a system into independently deployable services organized around business capabilities.

Core Idea

A microservices architecture decomposes an application into a set of small, autonomous services. Each service runs in its own process, owns its data, and communicates with other services through well-defined APIs or asynchronous messaging. Services are organized around business capabilities rather than technical layers.

API Gateway Order Service Payment Service Inventory Service Orders DB Payments DB Inventory DB — dashed lines = async messaging between services —

Each service owns its data store and communicates via APIs or events

Benefits

Costs

Operational Complexity

Running microservices in production requires significant investment in infrastructure and tooling:

Data Ownership

Each service owns its data store. No service should directly access another service's database. This ensures loose coupling and allows services to change their internal storage without affecting others.

When data needs to be shared, services communicate through APIs or events. This often leads to data duplication, which is an accepted trade-off for autonomy.

Service Boundaries

Good service boundaries are aligned with business capabilities, not technical functions. Signs of well-drawn boundaries:

Signs of poor boundaries:

Distributed Systems Problems

Microservices inherit all the challenges of distributed computing:

When Not to Use Microservices

If you cannot build a well-structured monolith, you will not be able to build a well-structured microservices system. Start with a modular monolith and extract services only when there is a clear need.

Related Styles