How services talk: interaction styles, API contracts, REST and gRPC, partial failure and service discovery.
key idea / coordinatorservice / good pathin progress / watch outproblem / failureneutral
Why IPC suddenly matters
In a monolith, modules call each other with plain method calls. Services are separate processes, so every call crosses the network and can fail.
Services run as separate processes, so they need interprocess communication (IPC).
In-process vs inter-process
A network call is not a method call with a longer wire. Four differences change how you design APIs.
Source: Building Microservices, chapter 4.
From Building Microservices: do not hide the network from developers. If a call crosses a process boundary, the code should make that visible so nobody is surprised by latency or failure.
Interaction styles
Think about the style before picking a technology. Asynchronous styles keep services loosely coupled.
Choosing a communication style
Pick the style first and the technology second. Newman starts by asking: request-response or event-driven?
Most systems mix styles. One service can offer a request-response API and also publish events.
From Building Microservices: Kafka for request-response, or a single-page-app framework for a plain website, are examples of a shiny tool in the wrong place. Start from the style you need.
Events, commands and requests
Both are messages, but they mean different things. A message is the envelope; the event or request is what it carries.
Rule of thumb: put in an event only what you would also share in a request-response API.
From Practical Event-Driven Microservices: a "just right" event avoids two traps. OrderStreetNumberChanged forces consumers to rebuild the address, while a huge event leaks other domains. Publish what consumers need, and involve them in the design.
APIs are contracts
A service and its clients are not compiled together, so a breaking change shows up as a runtime failure. Write the API definition first (API-first), then evolve it carefully.
Schemas and handling change
Make the interface explicit, then change it with care. Schemas catch structural breaks early.
From Building Microservices: a company that gave consumers a year to leave an old interface never checked who still used it. Always track callers, or you cannot remove the old endpoint safely or know who you will break.
Synchronous calls: REST and gRPC
Remote procedure invocation (RPI) means the client sends a request and waits for a reply.
REST, RPC and GraphQL compared
The synchronous options differ in what they assume about client and server.
Technology
Style
Best for
Watch out
gRPC / RPC
Sync, request-response
Internal calls you control at both ends
Schema coupling, hidden network cost
REST over HTTP
Sync, request-response
Many different clients, the perimeter
Few schemas by default, chatty
GraphQL
Sync queries
Edge: mobile and GUI aggregation
Caching, query load, mostly reads
SOAP
Sync RPC over HTTP
Legacy integration
Heavyweight, ignores HTTP verbs and codes
Message broker
Async
Events and long jobs
Another system to run
Handling partial failure
If a service is slow or down, callers can pile up and the failure spreads. Use timeouts, limit outstanding requests, and add a circuit breaker.
Also: use timeouts and cap the number of outstanding requests.
Finding services: service discovery
Instance addresses change as services scale and restart, so clients ask a registry. Prefer the platform's built-in discovery.
Discovery options and sharing code
Two practical questions: how do services find each other, and what can they share?
Also publish the catalog in a form people can browse, not only machines.
From Building Microservices: DRY means do not duplicate knowledge, but across service boundaries a little duplication is often cheaper than coupling. Netflix client libraries also carried discovery and failure handling, not only the API.
Recap
IPC is central in microservices. Choose styles, formats and versions deliberately.
REST and gRPC are synchronous. Protect them with timeouts and circuit breakers.
Use platform service discovery when you can.
Network calls differ from method calls: slower, can fail in five ways, and change across deploys.
Choose request-response or event-driven first. A command is a request to one service; an event is a published fact.
Make interfaces explicit with schemas, read tolerantly, and use expand and contract for breaking changes.
Quick check
Why does calling three 99.5% services in a row give only 98.5% availability?Show answer
A synchronous request needs all three to be up at once, so the probabilities multiply: 0.995 x 0.995 x 0.995 is about 0.985.
What is the difference between a structural and a semantic breaking change?Show answer
A structural break changes the shape of the interface (a field removed, a new required field), and a schema comparison can catch it. A semantic break keeps the shape but changes behavior, so only tests such as consumer-driven contracts catch it.