What is a microservices architecture?
In a microservices architecture one product is made of several small services instead of one large program. Each service does one job, is deployed on its own and is owned by one team. The price is that the services now have to find each other, talk over a network and stay correct when a neighbor is down.
This template shows the pieces that make that work: client apps, an API gateway, five services with a database each, an event bus and an observability stack. The example is a ride-hailing app, the kind where a rider requests a trip and a driver accepts it.
Two apps, one gateway, five services
At the top, a Rider app and a Driver app both call the API gateway over HTTPS. The gateway card lists its three duties: auth, routing, limits. From the gateway a single bar labeled “REST and gRPC” fans out to five services:
- Rider service: profiles, cards.
- Driver service: documents, status.
- Trip service: matching, trips.
- Pricing service: fares, surge.
- Payment service: charges.
Each service card also names the language it is written in, and the five cards name four different ones. That is a deliberate point of the example. Services agree on their interfaces, so each team can choose what suits the job.
One database per service
Under every service sits a cylinder, and no two services share one. The Rider service stores riders, the Driver service stores drivers, the Trip service keeps trips in a store of a different kind, the Pricing service keeps a fare cache, and the Payment service owns the ledger.
The first rule at the bottom of the board says why: Own your data. “Each service has its own database. No one else reads its tables.” When you fill in the template for your own system, this is the test for each box. If two services write to the same tables, they are one service with two names, and the drawing should show that honestly.
Events on the bus
A dashed arrow drops from every service to the Event bus, and the first one is labeled “publish”. The bus has one topic per event. Five topics are shown, each with its readers:
- rider.signed_up, read by Payment.
- driver.location, read by Trip.
- trip.completed, read by Payment and Pricing.
- fare.quoted, read by Trip.
- payment.captured, read by Trip and Rider.
Names follow one pattern: the thing, a dot, then what happened to it. An event states a fact. The Trip service does not tell Payment to charge anyone. It announces trip.completed, and Payment decides what to do. The second rule on the board sums it up as Ask or tell: ask through an API call, tell the others with an event.
Observability across services
One request now crosses several services, so the right-hand panel is not optional. Observability has four cards: metrics; dashboards and alerts; traces across services; and logs. The logs card adds “one trace ID”, which is what lets you follow a single ride through five sets of logs.
A dashed arrow labeled “telemetry” runs from the services to this panel. Draw it once, as the example does, instead of five times. The reader understands that every service reports.
How to use the microservices template
- Open it as a new board and rename the five services to yours. Add or remove a panel by copying a whole column, cylinder included.
- Write the two-word job under each service name. If you need a sentence, the service probably does too much.
- List your real topics on the bus. For each one fill in “Read by”. A topic nobody reads is a candidate for deletion.
- Check the three rules. Own your data, Ask or tell, and Fail alone: “Time out, retry with backoff and keep working when a neighbor is down.” Mark any service that breaks one.
The board has 137 elements. It opens on the Free plan, which allows 150, so a sixth service column may take you past the limit and need Pro.
When to draw this, and alternatives
Use it when you split a monolith and need to agree on boundaries, or to show a new team how existing services depend on each other. It is a map of services, not of servers.
If nearly everything in your system happens through events, the event-driven architecture template puts producers and consumers first. To show where the services run, use the Kubernetes deployment template. For one system seen from the outside, with its apps and stores, a C4 container diagram is the lighter choice.
Questions about the Microservices template
Why does each microservice need its own database?
So it can change its tables without breaking anyone else, and so it can be deployed alone. The board states the rule as Own your data. Other services get the data by calling the owner’s API or by reading the events it publishes.
When should services call each other and when should they publish events?
Call when you need an answer now, such as a fare before the rider confirms. Publish when you are reporting something that already happened, like trip.completed, and do not care who reacts. The template calls this Ask or tell.
What does an API gateway do?
It is the single entry point for the client apps. In the example it handles auth, routing and limits, so the five services behind it do not each repeat that work and the apps do not need to know where each service lives.
How many services should the diagram show?
As many as one team can reason about in a review: the example has five. If you run forty, draw one board per domain and show the other domains as single boxes, or the event bus becomes unreadable.