Microservices Communication Patterns
On this page
Symptom: one slow service slows every page
After splitting the monolith into microservices, a product page takes 1.2 seconds. Tracing shows the page calls the product service, which calls pricing, which calls promotions, which calls the customer service to check loyalty tier. Four hops in sequence, each with its own latency and failure rate. The code looks the same as before; the cost of each "function call" is a hundred times higher.
REST vs gRPC vs events between microservices
| Style | Strengths | Fits |
|---|---|---|
| REST over HTTP/JSON | Universal, readable, easy to debug and cache | Calls across team boundaries, external or partner APIs |
| gRPC over HTTP/2 | Typed contracts, compact binary, streaming, low overhead | High-volume internal calls between your own services (Day 16) |
| Asynchronous events/messages | No waiting, survives the receiver being down, fans out | Side effects and notifications where nobody needs an immediate answer (Days 41 to 45) |
The deciding question, again: does the caller need the answer right now to continue? If yes, synchronous. If not, an event.
Diagnose: long synchronous call chains
Each hop multiplies risk. Four services at 99.9 percent availability in sequence give about 99.6 percent for the chain (Day 4), and latency adds up, including tail latency: the chain is slow whenever any hop is slow.
Look for:
- long call chains in traces,
- a service that calls another for every request just to read data that rarely changes,
- "chatty" interactions: many small calls where one would do.
Fix: patterns that shorten or remove calls
Call in parallel. If the page needs product, price and stock, fetch them concurrently, not one after another. Latency becomes the slowest call, not the sum. In C#, start the calls and await Task.WhenAll(...). Don't share one EF Core DbContext across those parallel tasks; it isn't thread-safe and throws when used concurrently.
Keep a local copy of data you only read. The pricing service doesn't need to call the customer service for every price; it can keep a small table of customer tiers updated from CustomerTierChanged events. Event-carried state (Day 46) turns a runtime dependency into a data subscription.
Aggregate at the edge. A BFF or gateway (Day 18) makes the fan-out calls inside the data center and returns one response to the client.
Batch. One GET /prices?ids=1,2,3 instead of three calls.
Use events for anything not needed immediately. Analytics, emails and search indexing never belong in the request path.
Worked example: a call style for each checkout call
- Order → Inventory: "is this in stock?" Needed now to accept the order: synchronous, over gRPC internally, with a 200 ms timeout and a fallback ("we'll confirm availability by email") for non-critical cases.
- Order → Analytics, Recommendations, Email: nobody waits. Publish
OrderPlaced; they subscribe. - Order → Customer: "what's the loyalty discount?" Read from a local copy kept fresh by customer events, so checkout doesn't depend on the customer service being up.
Every synchronous call needs three things
- A timeout shorter than the caller's own deadline (Day 75).
- A retry policy with backoff, only for safe-to-retry requests (Day 74). Retry at one layer only: if each of four services in a chain retries 3 times, one failure at the bottom can become 3 × 3 × 3 × 3 = 81 calls.
- A circuit breaker so a failing dependency is skipped quickly instead of tying up threads (Day 56).
Check yourself
Call independent services in parallel, and replace calls for slowly changing data with a local copy kept up to date by events.
For high-volume internal calls between services you control, where compact binary messages, strongly typed generated clients, streaming and HTTP/2 multiplexing matter more than human-readable payloads and browser support. Public APIs and anything browsers call directly usually stay REST.
Retries multiply at each layer: 3 to the power of 4 is 81 calls per original request. Retry at one layer, usually the edge, and fail fast below it.
Keep the customer data it needs, such as loyalty tier, in its own store, updated from customer events, and read it locally.
A timeout, so a slow dependency can't hold resources forever; a bounded retry policy with backoff, applied only to safe operations; and a fallback or circuit breaker, so a failing dependency degrades the feature instead of the whole request.