Top 10 Design Patterns for Microservices Architecture
Microservices architecture solves the scaling and autonomy problems of monolithic systems, but it introduces a new set of challenges: distributed data, network failures, and complex cross-service transactions. The patterns below are the practical toolkit architects reach for when those challenges appear.
This guide covers ten patterns, each with a concrete example of when and how to apply it. Every pattern trades one problem for a smaller one — the trick is knowing which trade-off you can afford.
Why Microservice Patterns Matter
When you move from one deployable unit to dozens, every assumption you made about communication, transactions, and failure breaks. A method call that took one microsecond becomes a network call that might take 200ms — or never return at all. A single ACID transaction becomes a multi-step coordination problem.
These patterns exist because thousands of teams have hit the same walls. They are not optional cleverness — they are the standard responses to predictable failure modes.
1. Database per Service
A shared database couples services at the data layer, defeating independent deployability. One team’s schema change breaks another team’s queries.
Each service owns its data privately — separate physical databases or logically isolated schemas. Other services access it only through the owning service’s API.
In an e-commerce system, the Order Service owns the orders table, the Customer Service owns customers, and Inventory owns inventory. When Order needs customer data, it calls the Customer Service API — it never queries the customers table directly. The Customer team can change their schema without coordinating with the Order team.
Cross-service queries become harder, and ACID transactions across services are no longer possible. You need Saga and API Composition to compensate.
2. API Gateway
Clients calling dozens of microservices directly creates chatty communication, exposes internal topology, and duplicates concerns like authentication across every service.
A single entry point sits between clients and the backend. It routes requests, enforces auth, applies rate limits, and can aggregate responses from multiple services into one client-facing call.
A mobile app needs a “home screen” response that combines user profile, recent orders, and recommendations. Instead of the app making three calls, it calls /home on the API Gateway. The gateway fans out to the User, Order, and Recommendation services, combines the results, and returns one JSON payload.
The gateway becomes a single point of failure and a potential bottleneck. It must be highly available and horizontally scaled. It also adds a network hop.
3. Service Registry & Discovery
In a dynamic environment, service instances scale up and down, move between hosts, and get replaced. Hard-coded hostnames or IPs break constantly.
A registry (Consul, Eureka, etcd) tracks live instances. Services register on startup and deregister on shutdown. Callers query the registry to find healthy instances, often cached client-side.
An Order Service needs to call Inventory. Instead of calling http://10.0.1.42:8080, it asks the registry for inventory-service, gets back three healthy instances, and load-balances across them. When one instance is scaled down, the registry removes it within seconds.
The registry becomes critical infrastructure — if it’s down, discovery fails. Client-side caching and health checks are essential.
4. Circuit Breaker
When a downstream service is slow or down, callers keep retrying. Threads pile up waiting for timeouts, exhausting connection pools and cascading the failure upstream.
Wrap the call in a circuit breaker. After N consecutive failures, the breaker opens and all calls fail immediately (no network attempt). After a cooldown, it allows a few test calls (half-open). If they succeed, it closes again.
A Checkout Service calls the Payment Service. The Payment Service starts timing out at 30 seconds. Without a breaker, every checkout thread blocks for 30s. With a breaker set to open after 5 failures, the 6th checkout fails in 5ms with a “payment unavailable” message — the user gets a fast, clear error instead of a hung page.
Tuning thresholds is tricky. Too aggressive, and you open the breaker during normal blips. Too lenient, and you don’t protect the system. Libraries like Resilience4j and Polly make this manageable.
Rule of thumb: Wrap every synchronous call between services in a circuit breaker. The cost of adding it is minutes. The cost of not having it during an outage is measured in hours.
5. Saga Pattern
You can’t use a single ACID transaction across multiple services. If step 3 fails, steps 1 and 2 have already committed — you need to undo them.
Model the workflow as a saga: a series of local transactions, each publishing an event. If any step fails, the saga runs compensating transactions for the steps that already succeeded.
An order placement saga: (1) create order, (2) reserve inventory, (3) charge payment, (4) confirm order. If step 3 fails, the saga runs compensating transactions: release the inventory reservation (step 2) and cancel the order (step 1). The customer sees a clean “payment failed — order cancelled” message.
Sagas require careful design of compensating transactions — they’re not always straightforward (“un-send an email” isn’t a thing). Sagas also introduce eventual consistency: intermediate states are visible.
6. CQRS (Command Query Responsibility Segregation)
Reads and writes have different performance profiles, scaling needs, and consistency requirements. A single model optimized for both is optimized for neither.
Split the model: commands (writes) go to one service and storage; queries (reads) go to a separate, optimized read model — often denormalized, often cached, often a different database.
A product catalog: writes go to a normalized PostgreSQL database (the command side). Reads go to Elasticsearch (the query side) for fast, faceted search. When a product is updated, an event propagates the change to Elasticsearch. The write side never has to serve heavy search queries.
Reads and writes become eventually consistent. Users may see stale data for a brief window after a write. This is fine for catalogs, less fine for bank balances.
7. Event Sourcing
Traditional state storage loses history. You know the current balance but not how it got there. Auditing and debugging become archaeology.
Store every state change as an immutable event. The current state is computed by replaying events. Read models (via CQRS) materialize current state for queries.
An account ledger: instead of storing balance = 500, store events — Deposited(200), Withdrew(100), Deposited(400). Balance is derived by replaying. You get a full audit trail for free, and you can reconstruct state as of any past moment.
Event schema changes are hard — old events must still replay. Querying requires CQRS read models. Eventual consistency is unavoidable.
8. Strangler Fig (Monolith Migration)
Rewriting a monolith from scratch is high-risk, slow, and often fails. You need to deliver value continuously while the transition is in progress.
Place a proxy or API gateway in front of the monolith. Route one feature at a time to a new microservice. As more features migrate, the monolith “strangles” — shrinks until it can be retired.
A legacy e-commerce monolith serves everything. Start by routing only product search to a new Search microservice. Next, move checkout. Next, move user profiles. Each migration is small enough to test and roll back. Two years later, the monolith serves only admin routes — and gets retired.
You run two systems in parallel during the transition. The routing layer must be carefully managed, and the monolith may accumulate workarounds for the migrated features.
9. Sidecar / Service Mesh
Every service needs the same infrastructure concerns — retries, TLS, metrics, tracing, circuit breaking. Implementing them in every service in every language duplicates effort and creates inconsistency.
Deploy a sidecar proxy alongside each service (Envoy is the standard). All inbound and outbound traffic goes through the proxy, which handles cross-cutting concerns. A control plane (Istio, Linkerd) configures all sidecars consistently.
A team writes a Python service with zero networking code — just HTTP handlers. The sidecar handles mTLS, retries on 5xx, request tracing, and rate limiting. Meanwhile, a Go service in another team gets the exact same behavior from its sidecar, with no shared library dependency.
Service mesh adds latency (a proxy hop per request) and operational complexity. For small systems, it’s overkill — for large ones, it’s often essential.
10. Bulkhead
A single overwhelmed dependency can exhaust a shared resource pool (threads, connections), starving unrelated operations and taking down the entire service.
Partition resources into isolated pools per dependency or per operation type. If one pool is exhausted, the others are unaffected — like watertight compartments in a ship.
An API service has 200 threads. Without a bulkhead, a slow call to the Recommendations service can consume all 200 threads, breaking payment, login, and checkout. With bulkheads, allocate: 60 threads for Recommendations, 40 for Payment, 40 for Auth, 60 for general. If Recommendations saturates its 60, the other 140 stay healthy.
Bulkheads reduce peak utilization — a pool sized for worst-case traffic is idle most of the time. They also need tuning: too small, and you drop legitimate traffic; too large, and you lose isolation.
How These Patterns Work Together
These patterns are not isolated. In a real system, they form a layered defense:
At the edge, the API Gateway handles auth and routing. Between services, the sidecar enforces mTLS and observability. Each synchronous call is wrapped in a circuit breaker and compartmentalized by a bulkhead. Multi-service workflows use Sagas. Read-heavy services use CQRS, and audit-sensitive ones use Event Sourcing. Service discovery ties it all together, and Strangler Fig is the path that gets you from monolith to this state.
Common Mistakes When Adopting These Patterns
| Mistake | What happens | Better approach |
|---|---|---|
| Adopting all ten on day one | Complexity explosion before you have the traffic to justify it | Start with DB-per-Service and API Gateway; add others as they become necessary |
| Skipping circuit breakers | One slow service takes down the whole system | Add circuit breakers from the first inter-service call |
| Treating CQRS as default | Eventual consistency where users expect it instantly | Use CQRS only for genuinely read-heavy domains |
| Using Saga for everything | Compensating transactions become as complex as the original workflow | Use Saga only when a cross-service transaction is truly needed |
| Big-bang migration | Multi-year rewrite that risks failing completely | Use Strangler Fig — migrate one feature at a time |
Frequently Asked Questions
Do I need all ten patterns to run microservices?
No. Most teams start with three or four — Database per Service, API Gateway, Service Discovery, and Circuit Breaker. CQRS, Event Sourcing, and Service Mesh become relevant at larger scale or in specific domains (finance, e-commerce, real-time analytics).
What’s the difference between Saga and a distributed transaction?
A distributed transaction (2PC) holds locks across services until all commit — it’s ACID but doesn’t scale and has poor failure semantics. Saga abandons locks: each step commits locally, and on failure, compensating actions undo prior steps. The result is eventual consistency, not strict atomicity.
Is a service mesh required for microservices?
No. Small systems can handle cross-cutting concerns with a shared library or by configuring each service. Service mesh becomes valuable when you have dozens of services in multiple languages and need consistent mTLS, retries, and observability without touching each service’s code.
When should I use CQRS?
When read and write loads have very different shapes or magnitudes — for example, a product catalog with millions of reads and few writes. For domains where writes and reads are similar, CQRS adds complexity for little gain.
Is event sourcing a good fit for every aggregate?
No. Event sourcing works well for aggregates with meaningful history — ledgers, order timelines, audit logs. It’s overkill for simple CRUD entities like user profiles or configuration settings.
Which pattern should I learn first?
Database per Service and API Gateway — these define the fundamental shape of a microservices system. Then Circuit Breaker, because it’s the difference between a survivable outage and a cascading failure.
Final Verdict: Start With the Problem, Not the Pattern
The biggest mistake architects make is choosing patterns before choosing problems. Every pattern on this list solves a specific failure mode — but if you don’t have that failure mode yet, the pattern adds cost without benefit.
Start with Database per Service to enforce ownership and independent deployability. Add API Gateway when clients become chatty. Add Circuit Breakers the first time a downstream failure cascades. Add Saga the first time you genuinely need a cross-service workflow. Everything else is situational.
The mark of a mature architecture isn’t using the most patterns — it’s using the fewest patterns that let the system evolve safely.
These patterns map directly onto books like “Building Microservices” and “Microservices Patterns” — if you’re starting a migration, read those before writing code.