Microservices Component Diagram

When a shop is split into microservices, the important questions are: which services exist, what interface does each one offer, and what does each one depend on? A UML component diagram answers exactly that, using balls for interfaces a component provides and sockets for interfaces it requires.

This sample shows an API gateway in front of six services, an event broker and an external payment provider.


1. The Diagram

Online shop as components and interfaces «component» Web / mobile client «component» API Gateway routing, auth check, rate limits HTTPS /api «component» Identity Service owns users DB «component» Catalog Service owns catalog DB «component» Order Service owns orders DB «component» Inventory Service owns stock DB «component» Payment Service owns payments DB «component» Event Broker Kafka topic: orders «component» Notification Svc email + SMS «external» Payment Provider card network API ITokens ICatalog IOrders IInventory IPayments IPaymentProvider IEvents IEvents
  1. Clients only see one interface: HTTPS /api, provided by the API Gateway (highlighted). It checks tokens, applies rate limits and routes each call.
  2. The gateway requires three interfaces: ITokens from Identity, ICatalog from Catalog and IOrders from Order. Each ball-in-socket is an assembly connector: one side needs what the other offers.
  3. Order Service is the busiest: it requires IInventory to reserve stock, IPayments to take money and IEvents to publish OrderPlaced.
  4. Payment Service wraps the external Payment Provider, so only one component knows the card network API.
  5. Notification Svc also requires IEvents: it listens on the broker and never calls Order directly. That keeps the two decoupled.
  6. Each service note says which database it owns; no two services share a database.

2. How to Read It

Notation used «component» Name what it owns component (replaceable unit) provided interface (ball / lollipop) required interface (socket) assembly connector: need meets offer

Think of a plug and a wall outlet. Anything that provides the same interface can be swapped in without changing the components that require it, which is the whole idea of a component.

3. Variant: White-Box View of One Service

Variant: inside the Order Service «component» Order Service white-box view port: api port: payments port: inventory port: events IOrders IPayments IInventory IEvents REST controller Order logic Repository PostgreSQL Payment client Inventory client Outbox publisher Small squares are ports; arrows from a port to a part are delegation connectors.

Component diagrams nest. Zoom into Order Service and the outside interfaces attach to ports (small squares on the border). Inside, the REST controller hands requests to the order logic, which uses a repository and three outbound adapters. The outbox publisher writes events in the same database transaction as the order, then relays them to the broker, so an order is never saved without its event.

4. Pros and Cons

Pros

Cons

5. When to Use It

Use it when

Skip it when

6. As Diagrams-as-Code

The main diagram written for PlantUML:

@startuml
skinparam componentStyle uml2
component "Web / mobile client" as Client
component "API Gateway" as GW
component "Identity Service" as Id
component "Catalog Service" as Cat
component "Order Service" as Ord
component "Inventory Service" as Inv
component "Payment Service" as Pay
component "Event Broker" as Bus
component "Notification Svc" as Notif
component "Payment Provider" <<external>> as PSP

interface "HTTPS /api" as Api
interface ITokens
interface ICatalog
interface IOrders
interface IInventory
interface IPayments
interface IPaymentProvider
interface IEvents

GW -up- Api
Client -down-( Api
Id -- ITokens
Cat -- ICatalog
Ord -- IOrders
GW --( ITokens
GW --( ICatalog
GW --( IOrders
Inv -- IInventory
Ord --( IInventory
Pay -- IPayments
Ord --( IPayments
PSP -- IPaymentProvider
Pay --( IPaymentProvider
Bus -- IEvents
Ord --( IEvents
Notif --( IEvents
@enduml

In PlantUML, A -- I draws a provided interface (ball) and B --( I a required one (socket). Layout will differ from the hand-drawn SVG above.