Microservices Architecture Examples: 6 Patterns That Work
Microservices architecture is built from a few patterns: a gateway in front, a mesh between services, events for changes. Here are six of them, and when each fits.
On this page
Short answer
Microservices architecture examples worth studying are the API gateway, service mesh, event-driven design, CQRS, the saga pattern and the strangler fig pattern. Each one solves a specific problem that appears when a system is split into many services, and each one adds cost, so teams should adopt a pattern only when the problem it solves is real for them.
Which microservices architecture patterns matter most?
Microservices architecture is not one design. It is a set of patterns that teams combine: one pattern for how requests enter, one for how services talk, one for how data stays consistent. The table below maps the six patterns in this article to the problem each one solves.
| Pattern | Problem it solves | Best for | Cost |
|---|---|---|---|
| API gateway | One entry point for clients | Many clients, one system | Low |
| Service mesh | Safe calls between services | Many services, strict rules | High |
| Event-driven | Services react to changes | Loose coupling, async work | Medium |
| CQRS | Reads and writes scale apart | Heavy read load | Medium |
| Saga | Multi-service transactions | Orders, payments | High |
| Strangler fig | Replacing a monolith safely | Gradual migration | Low |
Start with the gateway and the strangler fig, and add the others only when the problem appears. A system with ten services does not need a service mesh, and a system with one writer does not need CQRS. The microservices explainer covers the basics of splitting a system before any pattern is chosen.
API gateway
1. API gateway: best for giving clients one entry point
An API gateway sits in front of all services and gives clients one address to call. It handles routing, authentication, rate limits and request shaping, so each service can stay simple and focused on its own job.
Without a gateway, every client must know where each service lives and how to call it, which breaks as soon as a service moves. The gateway also gives one place to log traffic and to block bad requests before they reach the services.
Pros:
- One address for all clients
- Auth and limits in one place
- Easy to change routing
Cons:
- Becomes a single point of failure
- Can grow into a bottleneck
- Needs its own scaling plan
Service mesh
2. Service mesh: best for safe calls between many services
A service mesh adds a small proxy beside each service that handles retries, timeouts, encryption and traffic rules between services. The application code makes a plain call, and the mesh makes it safe, observable and controlled.
The mesh fits systems with dozens of services, where hand-coding retries and security in each one would drift. It adds operational cost, so teams with a handful of services usually skip it and add it later.
Pros:
- Retries and timeouts built in
- Encrypted service-to-service calls
- Traffic rules without code changes
Cons:
- High operational cost
- Harder to debug when it fails
- Overkill for small systems
Event-driven design
3. Event-driven design: best for services that react to changes
In an event-driven design, a service publishes an event when something changes, such as an order being placed, and other services react to it. The services do not call each other directly, so one service can be down without blocking the rest.
Events make the system loose and easy to extend: a new service just subscribes to the events it needs. The cost is that the order of events and the handling of failures need careful design, or the system can process the same event twice.
Pros:
- Services stay independent
- Easy to add new consumers
- Handles bursts with queues
Cons:
- Event order needs care
- Debugging across services is harder
- Duplicate delivery must be handled
CQRS
4. CQRS: best for systems where reads and writes scale apart
CQRS separates the model that handles writes from the model that serves reads. Writes go through a command side that checks rules, and reads come from a view built for fast queries, which can be scaled and cached on its own.
The pattern fits systems where reads far outnumber writes, such as a shop where thousands of people browse and a few place orders. The read view can lag slightly behind the writes, which is fine for browsing but not for every case.
Pros:
- Reads scale without touching writes
- Read models fit the query
- Clear separation of concerns
Cons:
- Two models to maintain
- Read views can lag
- More moving parts
Saga pattern
5. Saga pattern: best for transactions across services
A saga is a series of local transactions across services, where each step has a compensating action that undoes it if a later step fails. An order saga might reserve stock, take payment and then book shipping, and if payment fails, the stock reservation is released.
Sagas replace the single database transaction that a monolith relied on. They keep services independent, but the team must design the rollback path for every step, which is work that is easy to skip and hard to add later.
Pros:
- No shared database needed
- Services stay independent
- Clear failure handling
Cons:
- Every step needs a rollback
- Partial states are visible
- Testing is more complex
Strangler fig pattern
6. Strangler fig pattern: best for replacing a monolith safely
The strangler fig pattern replaces a monolith piece by piece. New requests for one feature go to a new service, while the rest still go to the old system, and over time the new services take over until the monolith can be retired.
It is the safest way to migrate, because each step is small and reversible. Teams start with the feature that changes most often or hurts most, prove the new service in production, and only then move the next piece.
Pros:
- Small, reversible steps
- Old system keeps running
- Risk stays low
Cons:
- Two systems run at once
- Migration takes months
- Shared data needs care
How to choose microservices patterns
Choose microservices patterns by the problem you already have, not by the pattern you want to try. A pattern adopted without its problem adds cost and teaches nothing.
- Start with the gateway. One entry point is useful from the first service.
- Pick the strangler fig for migration. Replace the monolith piece by piece, starting with the busiest feature.
- Add events when services need to react. Direct calls are fine until one service blocks another.
- Add a saga when money moves across services. Orders and payments need a rollback plan.
- Add the mesh last. Only when the service count and the security rules justify the cost.
Company stories show the same order in practice. The real-world microservices examples describe how large teams split their systems.
The microservices versus monolith comparison helps decide whether to split at all, before any pattern is chosen.
What are the common mistakes?
The most common mistakes are adopting patterns before the problem exists, splitting too early, and forgetting the data. Each one turns a useful pattern into overhead.
- Adding a service mesh to ten services. The operational cost outweighs the benefit at that size.
- Splitting before the boundaries are clear. Services that chat constantly should have stayed one service.
- Sharing one database. Shared tables couple services as tightly as a monolith did.
- No rollback in a saga. A failed step without a compensating action leaves the system half done.
- Forgetting the gateway. Clients that call services directly break whenever a service moves.
Keep the pattern count small. A system that uses two patterns well is easier to run than one that uses six badly, and the extra patterns can be added when the need is proven.
Key takeaways
- Microservices architecture is a set of patterns, not one design
- Start with an API gateway and the strangler fig pattern
- Events, sagas and CQRS each solve one specific problem
- A service mesh only pays off when the service count is high
- Adopt a pattern when its problem appears, not before
Frequently asked questions
What is the simplest microservices architecture to start with?
Start with a few services behind an API gateway, each with its own database. Add events when services need to react to each other, and add the other patterns only when a specific problem appears, such as a transaction that spans services.
Do microservices need a service mesh?
No. A service mesh helps when dozens of services need retries, encryption and traffic rules between them. A small system can rely on the gateway and on simple libraries for retries, and add a mesh later when the service count grows.
What is the difference between an API gateway and a service mesh?
A gateway sits in front of the system and serves clients, handling routing and authentication. A mesh sits between services and handles calls inside the system, such as retries and encryption. Most systems use a gateway first and a mesh only later.
When should I use event-driven microservices?
Use events when services need to react to changes without calling each other directly, such as an order service notifying shipping and billing. Events add complexity around ordering and duplicates, so direct calls are fine for simple, synchronous work.
How do microservices handle transactions?
They use sagas: a series of local transactions where each step has a compensating action that undoes it if a later step fails. This keeps services independent, but the rollback path must be designed for every step, or the system can end up half done.
Is the strangler fig pattern only for monoliths?
It is mainly for replacing a monolith, but the same idea works for replacing any old system. Route new traffic to the new service, keep the old one running for the rest, and retire it piece by piece until nothing depends on it.