Chapter 8: Interprocess communication in a microservice architecture
The introduction explains why interprocess communication is central to microservices and why choosing an IPC mechanism is an architectural decision.
After this chapter you will be able to
- IPC across service boundaries. Explain why IPC has a more central role in a microservice architecture than in a monolith, and how it supports operations that span services.
- IPC choice as architecture. Justify why selecting an IPC mechanism requires weighing trade-offs rather than treating mechanisms as interchangeable.
- Synchronous and asynchronous IPC options. Distinguish synchronous request/response IPC, such as HTTP-based REST or gRPC, from asynchronous message-based IPC implemented through brokers such as Apache Kafka or RabbitMQ.
- Interaction style before technology. Explain why a service designer should consider how clients and services interact before choosing an IPC mechanism.
- Two interaction style dimensions. Distinguish the one-to-one versus one-to-many and synchronous versus asynchronous dimensions used to categorize interactions.
- One-to-one interaction variants. Describe request/response, asynchronous request/response, and one-way notifications in terms of the reply the client expects.
- Interaction style versus IPC technology. Explain why using messaging does not by itself make a request/response interaction asynchronous or loosely coupled.
- One-to-many publication variants. Distinguish publish/subscribe from publish/async responses, and describe how a service can combine interaction styles.
- Service API contracts. Distinguish in-process interfaces in a monolith from language-neutral, network-based service APIs, and describe what an HTTP or messaging API specifies.
- Interface definitions for compatibility. Explain why independently compiled services need an Interface Definition Language and what an IDL provides.
- API-first client collaboration. Describe the API-first sequence and justify reviewing the definition with client developers before implementing the service.
- API quality measures and commitments. Distinguish an SLI, an SLO, and an SLA, and explain why an API needs operational promises as well as a functional contract.
- Observability for measurable objectives. Explain why an SLO requires API instrumentation and observability to be useful.
- Error budgets and team priorities. Explain how an error budget is derived from an SLO and how its consumption affects a team’s priorities.
- Secure API Communication. Explain how TLS protects traffic between API clients and services and why that protection is foundational to API security.
- API Caller Authentication. Describe authentication as verifying who makes an API request and explain how access tokens can convey identity claims.
- Authenticated Caller Authorization. Distinguish authorization from authentication and describe how policies restrict an identified caller’s actions and resources.
- Independent Clients and API Evolution. Explain why changing an API is harder in a microservice architecture than in a monolith. Describe how independently deployed clients and rolling upgrades prevent a service from assuming that everyone uses the new API at once.
- Semantic API Version Numbers. State what MAJOR, MINOR, and PATCH indicate when applying semantic versioning concepts to APIs. Describe where a version number can appear in a REST or messaging API.
- Compatible and Breaking Changes. Distinguish preferred backward-compatible changes from unavoidable breaking changes. Explain why a service must temporarily support old and new API versions when it makes a breaking change.
- Breaking Change Detection. Describe the two approaches given for detecting accidental breaking changes: comparing schema versions and running consumer-driven contract tests. Explain how contracts can judge compatibility against actual client expectations rather than treating every removed field as breaking.
- Cross-language payload choice. Explain why a microservice’s message payload format must work across languages, even when all its services currently use one language.
- Text format tradeoffs and schemas. Describe why JSON and XML are easy for people and consumers to use, what schemas add, and why text can be inefficient.
- Binary formats and generated code. Explain the efficiency and tooling tradeoff of Protocol Buffers and Avro, including how their typed IDLs are used.
- Protocol Buffers and Avro fields. Distinguish how Protocol Buffers and Avro encode fields and what each approach requires of a consumer.
- Avro registry and schema resolution. Trace how a schema registry lets an Avro consumer obtain the writer schema and reconcile it with its own schema as producers and consumers evolve.
- Client message models. Explain how an API client uses DTOs to send and receive messages, and why its DTOs may represent only the parts of a service’s schema that it uses.
- DTO strategy trade-offs. Describe the factors used to choose a client message-model strategy, including why modeling unused API fields increases design-time coupling.
- RPI request and response. Explain that with RPI, a client sends a request to a service and expects a timely response, whether the client blocks while waiting or uses a non-blocking architecture.
- RPI proxy and server adapters. Trace how the client’s business logic calls a proxy interface, the proxy sends the request to a server adapter, and the server adapter calls the service’s business logic before the reply returns through the proxy. Describe the proxy interface as an encapsulation of the communication protocol.
- RPI Request Reply Benefits. Explain why RPI is easy to adopt and well suited to requests that need an immediate response, and why direct communication can simplify the system.
- Synchronous Runtime Coupling. Explain why an RPI request depends on both parties being available and responsive, and how a slow or failing service can affect its caller.
- REST Resources and Maturity Levels. Explain how REST uses URLs and HTTP verbs to work with resources, and distinguish the four levels of the REST maturity model.
- Backward-Compatible REST API Evolution. Distinguish non-breaking REST/JSON changes from breaking ones and describe how old and new API versions can coexist while clients migrate.
- REST Resource Design Challenges. Explain why fetching related objects and expressing complex updates can be awkward in REST, and describe the remedies presented here.
- REST Benefits and Runtime Costs. Describe REST's practical advantages and its request/response limitations for microservice communication.
- gRPC contracts and generated code. Explain how a gRPC API is defined and how its client and server code is produced. Describe what the generated code does when a client invokes a service method.
- Compatible gRPC API evolution. Distinguish backward-compatible additions to a gRPC API from breaking changes, and describe how the section handles each.
- gRPC benefits and limitations. Explain why gRPC can suit service-to-service communication while identifying the limitations this section highlights.
- Synchronous runtime coupling risks. Explain why a synchronous call makes the caller dependent on the downstream service’s response time and availability, and why that threatens the caller’s SLOs.
- Circuit breaker state transitions. Trace how a circuit breaker moves among closed, open, and half-open states, and explain why it temporarily stops calls after excessive failures.
- Case by case fallbacks. Explain why preventing cascading failure does not itself give the client a useful answer, and apply the section’s Order-versus-Delivery example to decide when a fallback is appropriate.
- Need for service discovery. Explain why a client cannot generally rely on hardcoded service addresses in a cloud-based microservices application, and describe the service registry’s basic role.
- Application-level discovery flow. Trace self registration and client-side discovery: identify who registers an instance, who queries the registry, and who chooses the request destination.
- Platform-provided discovery flow. Trace third-party registration and server-side discovery, including what the client addresses and who routes its request.
- Asynchronous service messaging. Explain that services communicate by asynchronously exchanging messages, usually through a message broker but sometimes directly in a brokerless architecture.
- Messaging interaction styles. Distinguish asynchronous request/reply, one-way notification, and publish/subscribe by whether a reply is expected and who consumes a published event.
- Messaging flow and adapters. Trace a message from a sender’s business logic through a sending port, sender adapter, and channel to a receiver adapter and receiving port.
- Message contents and kinds. Describe a message’s header and body, and distinguish documents, events, commands, and replies.
- Channel delivery semantics. Distinguish point-to-point from publish-subscribe channels by who receives each message and the interaction style each supports.
- Asynchronous messaging advantages. Explain how asynchronous messaging reduces availability and location dependencies, buffers work, and makes remote communication explicit.
- Messaging request and response. Explain how asynchronous request/response works with messaging and how it differs from request/response that expects an immediate reply.
- Publish-subscribe event channels. Explain how publish/subscribe messaging delivers domain events to interested services.
- Published requests with asynchronous replies. Trace how publish/async responses combines publication with reply matching.
- Requirements-first broker selection. Explain the two-step approach: define each message channel’s requirements, then choose messaging technology that supports them, rather than starting with a particular broker.
- Message channel requirements. Describe the kinds of requirements to establish for each channel, including channel type, delivery and ordering, competing consumers, persistence, durability, scalability, and latency. Distinguish surviving a broker crash from retaining messages for a disconnected consumer.
- Broker capability trade-offs. Describe how brokers differ in delivery guarantees, ordering, persistence, durability, scalability, and latency, and explain why the choice depends on the channel’s requirements rather than a universally best broker.
- Message longevity and compatibility. Explain why evolving an asynchronous API requires compatibility with older messages, not just currently running services.
- Added event attribute compatibility. Describe what consumers must handle when an attribute is added to an event, including the default-value difference between JSON or ProtoBuf and AVRO.
- Event type replacement transition. Explain how dual publishing lets an event type be replaced without immediately breaking existing consumers, and why older events may still matter afterward.
- Asynchronous API contract scope. Explain why a messaging API contract must describe both message structure and how messages flow between a service and its channels. State that AsyncAPI is a machine-readable IDL for asynchronous messaging APIs, not only event APIs.
- AsyncAPI document building blocks. Describe the roles of channels, messages, and operations in an AsyncAPI document, including what message schemas and send or receive operations specify.
- Shard keyed receiver assignment. Describe how sharded channels, a message’s shard key, and assignment of each shard to one receiver preserve ordering while allowing multiple receivers to work.
- At-least-once delivery and duplicates. Explain why brokers commonly provide at-least-once delivery and how a message can be delivered again after it has been processed.
- Idempotent handlers and ordering. Distinguish when repeated execution of a handler is harmless from when it needs duplicate detection, and explain why redelivery order matters.
- Transactional message ID tracking. Describe how a consumer uses processed message IDs to discard duplicates, including where it can store those IDs.
- Atomic database and message updates. Explain why a service must record a message atomically with the business-data change that requires it, and how the transactional outbox achieves this in a relational database.
- Polling publisher workflow and limits. Trace how a polling MessageRelay publishes outbox messages and explain when polling becomes less attractive.
- Transaction-log tailing relay. Explain how transaction-log tailing publishes recorded messages and contrast its tradeoff with polling.
- Response After Processing Completes. Explain how the Order Service can wait for other services to finish processing before responding to POST /orders, and why that choice affects the endpoint’s latency and availability.
- Response Before Asynchronous Validation. Describe how the Order Service can respond after starting message-based processing, and explain the resulting benefits and obligations for the client.
- Higher-level messaging library rationale. Explain the drawbacks of using a message broker’s client library directly and why the examples use Eventuate instead.
- Basic messaging API behavior. Describe how Eventuate’s basic producer and consumer APIs send and receive messages, and identify the patterns each implements.
- Higher-level messaging APIs. Distinguish Eventuate’s domain-event and command messaging APIs and explain how they sit on top of basic messaging.
What it builds on
- Operations in a microservice architecture (chapter 7) · Some operations in a microservice architecture span services.
- Runtime coupling (chapter 4) · Runtime coupling is a dimension of coupling.
- Benefits of loose design-time coupling (chapter 4) · Uses the value of loose design-time coupling between elements.
- Essential characteristic #1: Services are independently deployable (chapter 7) · Assumes services can be deployed independently.
- Architecting for observability (chapter 5) · The earlier discussion of architecting for observability.
- Design-time coupling (chapter 4) · The meaning and significance of design-time coupling.
- The structure of a service (chapter 7) · Assumes the distinction between a service’s business logic and its interfaces.
Section by section
Introduction
The introduction explains why interprocess communication is central to microservices and why choosing an IPC mechanism is an architectural decision.
- IPC across service boundaries: Explain why IPC has a more central role in a microservice architecture than in a monolith, and how it supports operations that span services.
Why it matters: It explains why communication between services needs architectural attention rather than being treated like an internal method call. - IPC choice as architecture: Justify why selecting an IPC mechanism requires weighing trade-offs rather than treating mechanisms as interchangeable.
Why it matters: The communication choice can shape how reliably and efficiently services work together.
Key terms: interprocess communication (IPC), service collaboration patterns, process boundaries, IPC mechanism, availability, performance, runtime coupling, transaction management
8.1 Overview of interprocess communication in a microservice architecture
This section introduces the main communication mechanisms and message payload formats available to microservices before turning to their design details.
- Synchronous and asynchronous IPC options: Distinguish synchronous request/response IPC, such as HTTP-based REST or gRPC, from asynchronous message-based IPC implemented through brokers such as Apache Kafka or RabbitMQ.
Why it matters: This distinction frames the two broad communication options developed later in the chapter. - Text and binary payload formats: Describe the section’s distinction between human-readable text message payload formats and more compact binary formats, with examples of each.
Why it matters: The communication mechanism is not the only IPC choice; the message payload format is another.
Key terms: synchronous request/response, asynchronous, message-based communication, message brokers, message payload formats, human-readable, text-based formats, compact binary formats
8.1.1 Interaction styles
Classifies client-service interaction styles and explains why the style should be chosen before an IPC technology.
- Interaction style before technology: Explain why a service designer should consider how clients and services interact before choosing an IPC mechanism.
Why it matters: It helps you make a communication design choice based on what the interaction requires. - Two interaction style dimensions: Distinguish the one-to-one versus one-to-many and synchronous versus asynchronous dimensions used to categorize interactions.
Why it matters: These two dimensions provide a way to describe an interaction without naming a technology. - One-to-one interaction variants: Describe request/response, asynchronous request/response, and one-way notifications in terms of the reply the client expects.
Why it matters: The expected reply changes what the client must do after sending a request. - Interaction style versus IPC technology: Explain why using messaging does not by itself make a request/response interaction asynchronous or loosely coupled.
Why it matters: It prevents you from assuming that a messaging technology removes the dependency created by waiting for a reply. - One-to-many publication variants: Distinguish publish/subscribe from publish/async responses, and describe how a service can combine interaction styles.
Why it matters: It clarifies whether a published message merely notifies subscribers or solicits responses.
Key terms: interaction style, IPC mechanism, availability, one-to-one, one-to-many, synchronous, asynchronous, request/response, asynchronous request/response, one-way notifications
8.1.2 Defining APIs in a microservice architecture
This section explains how to define reliable service API contracts using interface definitions, API-first collaboration, and shared style conventions.
- Service API contracts: Distinguish in-process interfaces in a monolith from language-neutral, network-based service APIs, and describe what an HTTP or messaging API specifies.
Why it matters: The form of a service contract determines what independently developed clients and services must agree on. - Interface definitions for compatibility: Explain why independently compiled services need an Interface Definition Language and what an IDL provides.
Why it matters: A formal contract helps catch incompatibilities that a shared build cannot catch for independently deployed services. - API-first client collaboration: Describe the API-first sequence and justify reviewing the definition with client developers before implementing the service.
Why it matters: Completing the client and service separately is not enough if they disagree about their API. - Shared API style conventions: Explain how an organizational API style guide makes independently developed service APIs more consistent and easier to use.
Why it matters: A shared style keeps independently designed APIs predictable for their consumers.
Key terms: service API, network-based contract, HTTP, messaging, Interface Definition Language (IDL), Open API, AsyncAPI, compatibility checks, API-first, interface definition
8.1.3 APIs have Service Level Objectives (SLOs)
The section explains how measurable API quality targets, observability, and error budgets turn operational promises into decisions about service reliability and delivery.
- API quality measures and commitments: Distinguish an SLI, an SLO, and an SLA, and explain why an API needs operational promises as well as a functional contract.
Why it matters: These distinctions make expectations about service quality concrete rather than merely aspirational. - Observability for measurable objectives: Explain why an SLO requires API instrumentation and observability to be useful.
Why it matters: A target helps a team only if it can see whether the service is meeting it. - Error budgets and team priorities: Explain how an error budget is derived from an SLO and how its consumption affects a team’s priorities.
Why it matters: The budget gives teams an objective signal for balancing delivery speed against reliability work.
Key terms: service level indicator, service level objective, service level agreement, software quality attributes, observability, instrumentation, telemetry, SLI, SLO, error budget
8.1.4 API Security
This section explains three distinct API security concerns: protecting communication, verifying callers, and controlling their access.
- Secure API Communication: Explain how TLS protects traffic between API clients and services and why that protection is foundational to API security.
Why it matters: Protecting the connection prevents network attacks from defeating other API security measures. - API Caller Authentication: Describe authentication as verifying who makes an API request and explain how access tokens can convey identity claims.
Why it matters: An API must establish the caller’s identity before it can decide what that caller may access. - Authenticated Caller Authorization: Distinguish authorization from authentication and describe how policies restrict an identified caller’s actions and resources.
Why it matters: Knowing who a caller is does not mean that caller should be allowed to do everything.
Key terms: secure communication, Transport Layer Security (TLS), data in transit, authentication, access tokens, OAuth 2.0 bearer tokens, JSON Web Tokens (JWTs), identity claims, authorization, role-based access control
8.1.5 Evolving APIs
This section explains why service APIs need controlled evolution and how versioning, compatibility practices, and automated checks help prevent breaking clients.
- Independent Clients and API Evolution: Explain why changing an API is harder in a microservice architecture than in a monolith. Describe how independently deployed clients and rolling upgrades prevent a service from assuming that everyone uses the new API at once.
Why it matters: Independent deployment makes compatibility a practical requirement, not just a preference. - Semantic API Version Numbers: State what MAJOR, MINOR, and PATCH indicate when applying semantic versioning concepts to APIs. Describe where a version number can appear in a REST or messaging API.
Why it matters: A version number communicates the kind of API change clients may need to handle. - Compatible and Breaking Changes: Distinguish preferred backward-compatible changes from unavoidable breaking changes. Explain why a service must temporarily support old and new API versions when it makes a breaking change.
Why it matters: Supporting both versions gives independently deployed clients time to move without an immediate outage. - Breaking Change Detection: Describe the two approaches given for detecting accidental breaking changes: comparing schema versions and running consumer-driven contract tests. Explain how contracts can judge compatibility against actual client expectations rather than treating every removed field as breaking.
Why it matters: Automated checks can catch outages before deployment without treating every unused API field as indispensable.
Key terms: API, clients, rolling upgrade, Semantic Versioning, MAJOR.MINOR.PATCH, REST API, messaging, backward-compatible changes, major, incompatible changes, side-by-side API
8.1.6 Message payload formats
Explains how message payload formats affect interoperability, efficiency, API usability, and schema evolution, comparing text formats with Protocol Buffers and Avro.
- Cross-language payload choice: Explain why a microservice’s message payload format must work across languages, even when all its services currently use one language.
Why it matters: A format that works today must not block future services written in other languages. - Text format tradeoffs and schemas: Describe why JSON and XML are easy for people and consumers to use, what schemas add, and why text can be inefficient.
Why it matters: Text formats favor readability and flexible consumption, but their size and parsing cost can matter. - Binary formats and generated code: Explain the efficiency and tooling tradeoff of Protocol Buffers and Avro, including how their typed IDLs are used.
Why it matters: Binary formats can improve throughput, but teams must account for their tooling and development workflow. - Protocol Buffers and Avro fields: Distinguish how Protocol Buffers and Avro encode fields and what each approach requires of a consumer.
Why it matters: The encoding determines whether a consumer can interpret a message using its local schema or must obtain the writer’s schema. - Avro registry and schema resolution: Trace how a schema registry lets an Avro consumer obtain the writer schema and reconcile it with its own schema as producers and consumers evolve.
Why it matters: This arrangement preserves Avro’s compact encoding while allowing independently deployed producers and consumers to evolve safely.
Key terms: IPC, message payload format, cross-language message payload format, Java serialization, JSON, XML, self-describing, JSON Schema, backward-compatible, text-based message format
8.1.7 Developing API clients
This section explains how API clients represent exchanged messages and compares four implementation strategies by effort, correctness, type safety, and design-time coupling.
- Client message models: Explain how an API client uses DTOs to send and receive messages, and why its DTOs may represent only the parts of a service’s schema that it uses.
Why it matters: The client’s message model must support communication without necessarily mirroring everything the service exposes. - DTO strategy trade-offs: Describe the factors used to choose a client message-model strategy, including why modeling unused API fields increases design-time coupling.
Why it matters: The easiest DTOs to create are not necessarily the safest or least coupled to the service. - Untyped message structures: Explain the advantages and disadvantages of representing client payloads with untyped maps or dictionaries.
Why it matters: Untyped messages save work, but mistakes may remain invisible until the client runs. - Schema-generated DTO classes: Explain what generating DTOs from a service schema provides and what costs or coupling it can introduce.
Why it matters: Generation improves schema fidelity but can complicate builds and tie a client to more of the API than it uses. - Handwritten DTO trade-offs: Describe why a team might handwrite or trim generated DTOs and how it must account for API changes.
Why it matters: A smaller, tailored client model shifts responsibility for keeping it aligned with the API onto the client team. - Service-provided client libraries: Explain the reuse benefits and consumer costs of using a client library published by the service team.
Why it matters: Sharing a client library prevents duplicated integration code but trades away some consumer independence.
Key terms: API client, Data Transfer Objects (DTOs), serialization, deserialization, projection, development effort, correctness, type safety, design-time coupling, untyped data model
8.2 Communicating using the synchronous remote procedure invocation pattern
Introduces synchronous remote procedure invocation (RPI) as a request–response way for a client to communicate with a service, and traces the request through client and server adapters.
- RPI request and response: Explain that with RPI, a client sends a request to a service and expects a timely response, whether the client blocks while waiting or uses a non-blocking architecture.
Why it matters: The expectation of a timely reply distinguishes RPI from the messaging style described here. - RPI proxy and server adapters: Trace how the client’s business logic calls a proxy interface, the proxy sends the request to a server adapter, and the server adapter calls the service’s business logic before the reply returns through the proxy. Describe the proxy interface as an encapsulation of the communication protocol.
Why it matters: This path shows where remote communication fits around the client’s and service’s business logic.
Key terms: remote procedure invocation, RPI, request, response, proxy interface, RPI proxy adapter class, RPI server adapter class, business logic
8.2.1 Benefits and drawbacks of RPI
This section weighs RPI’s familiar, direct request/reply model against its runtime coupling, limited interaction styles, and need for service discovery.
- RPI Request Reply Benefits: Explain why RPI is easy to adopt and well suited to requests that need an immediate response, and why direct communication can simplify the system.
Why it matters: These benefits explain why RPI remains a common choice despite its drawbacks. - Synchronous Runtime Coupling: Explain why an RPI request depends on both parties being available and responsive, and how a slow or failing service can affect its caller.
Why it matters: The immediate reply that makes RPI convenient also creates a risk when the called service is slow or unavailable. - Interaction Style Limits: Distinguish RPI’s natural request/reply support from interaction styles that require additional infrastructure.
Why it matters: A communication style that fits immediate replies may not fit every interaction a system needs. - Service Location Requirement: Explain why an RPI client needs service discovery and what kind of location information it can provide.
Why it matters: Direct communication still requires a way to find the service being called.
Key terms: Remote Procedure Invocation (RPI), request/reply, message broker, runtime coupling, high latency, resiliency patterns, interaction styles, event streaming platform, service discovery, network location
8.2.2 Using REST
Explains how REST APIs use resources and HTTP, how to define and evolve their contracts, and where REST is useful or awkward in a microservice architecture.
- REST Resources and Maturity Levels: Explain how REST uses URLs and HTTP verbs to work with resources, and distinguish the four levels of the REST maturity model.
Why it matters: The levels help you describe what an API actually does rather than calling every HTTP API RESTful. - Machine-Readable REST API Contracts: Describe what an OpenAPI document specifies and how generating it from service code can help keep the contract current.
Why it matters: A usable, current contract makes an API easier for clients and tools to work with. - Organization-Wide REST Conventions: Justify a REST API style guide by explaining which design choices it standardizes and how a microservice chassis can help enforce them.
Why it matters: Consistent conventions spare API consumers from learning different rules for every service. - Backward-Compatible REST API Evolution: Distinguish non-breaking REST/JSON changes from breaking ones and describe how old and new API versions can coexist while clients migrate.
Why it matters: Version coexistence gives clients time to update without an immediate service disruption. - REST Resource Design Challenges: Explain why fetching related objects and expressing complex updates can be awkward in REST, and describe the remedies presented here.
Why it matters: These limitations affect both client latency and how clearly an API expresses business operations. - REST Benefits and Runtime Costs: Describe REST's practical advantages and its request/response limitations for microservice communication.
Why it matters: The trade-off clarifies when REST's simplicity comes with availability and location dependencies.
Key terms: resource, HTTP verbs, REST maturity model, HATEOAS, OpenAPI Specification, OpenAPI document, IDL, API contract, REST API style guide, microservice chassis
8.2.3 Using gRPC
This section explains how gRPC defines and implements service APIs, how those APIs evolve, and when gRPC is a useful alternative to REST.
- gRPC contracts and generated code: Explain how a gRPC API is defined and how its client and server code is produced. Describe what the generated code does when a client invokes a service method.
Why it matters: The contract and generated code explain how services written in different languages can make strongly typed calls. - Compatible gRPC API evolution: Distinguish backward-compatible additions to a gRPC API from breaking changes, and describe how the section handles each.
Why it matters: These rules let a service change without immediately forcing every client to update. - gRPC benefits and limitations: Explain why gRPC can suit service-to-service communication while identifying the limitations this section highlights.
Why it matters: Choosing gRPC requires weighing its service-to-service strengths against browser support, complexity, and runtime coupling.
Key terms: gRPC, Protocol Buffers-based IDL, protoc, client-side stubs, server-side skeletons, backward-compatible changes, numeric field tags, breaking change, major version number, REST/JSON
8.2.4 Implementing resilient synchronous communication
This section explains how services making synchronous calls can limit the effects of downstream latency and failure, and still return useful responses when possible.
- Synchronous runtime coupling risks: Explain why a synchronous call makes the caller dependent on the downstream service’s response time and availability, and why that threatens the caller’s SLOs.
Why it matters: This dependency is why resilience belongs in the design of a synchronous client. - Resiliency pattern roles: Distinguish the basic roles of the listed resiliency patterns in limiting load, waiting, or repeated failures, versus providing a useful response when the primary path fails.
Why it matters: The patterns address different failure risks, so one does not substitute for all the others. - Circuit breaker state transitions: Trace how a circuit breaker moves among closed, open, and half-open states, and explain why it temporarily stops calls after excessive failures.
Why it matters: Failing fast avoids wasting calls and gives an unhealthy downstream service a chance to recover. - Case by case fallbacks: Explain why preventing cascading failure does not itself give the client a useful answer, and apply the section’s Order-versus-Delivery example to decide when a fallback is appropriate.
Why it matters: A useful degraded response depends on which missing information the client actually needs. - Client proxy resilience implementation: Describe the implementation options given for applying resiliency logic to Java RPI proxy calls.
Why it matters: Resiliency logic can be applied at the client proxy rather than re-created inside each remote call.
Key terms: runtime coupled, SLOs, resiliency patterns, Bulkhead, Cache, Circuit breaker, Fallback, Rate limiter, Retry, closed state
8.2.5 Using service discovery
The section explains why dynamic service locations require discovery, how application-level and platform-provided discovery work, and why platform-provided discovery is usually preferred.
- Need for service discovery: Explain why a client cannot generally rely on hardcoded service addresses in a cloud-based microservices application, and describe the service registry’s basic role.
Why it matters: Discovery lets a client reach a running instance even as deployments change. - Application-level discovery flow: Trace self registration and client-side discovery: identify who registers an instance, who queries the registry, and who chooses the request destination.
Why it matters: This approach puts both registration and destination selection in application-side components. - Platform-provided discovery flow: Trace third-party registration and server-side discovery, including what the client addresses and who routes its request.
Why it matters: The platform can handle changing instance locations without making each client perform discovery. - Discovery approach tradeoffs: Distinguish the benefits and drawbacks of application-level and platform-provided discovery, and justify the section’s usual preference.
Why it matters: The choice depends on whether platform independence and client control outweigh application-side complexity.
Key terms: service discovery, service registry, service instance, network location, Self registration pattern, Client-side discovery pattern, load-balancing algorithm, 3rd party registration pattern, Server-side discovery pattern, registrar
8.3 Communicating using the asynchronous messaging pattern
Introduces asynchronous messaging between services, its brokered and brokerless forms, and three client interaction styles.
- Asynchronous service messaging: Explain that services communicate by asynchronously exchanging messages, usually through a message broker but sometimes directly in a brokerless architecture.
Why it matters: This is the basic communication model behind the messaging pattern. - Messaging interaction styles: Distinguish asynchronous request/reply, one-way notification, and publish/subscribe by whether a reply is expected and who consumes a published event.
Why it matters: The styles describe different expectations about replies and event consumers.
Key terms: messaging, message broker, brokerless architecture, asynchronous request/reply, one-way notification, publish/subscribe
8.3.1 Overview of messaging
This section explains how messages move between services through channels, what messages and channels contain or do, and the benefits and costs of asynchronous messaging.
- Messaging flow and adapters: Trace a message from a sender’s business logic through a sending port, sender adapter, and channel to a receiver adapter and receiving port.
Why it matters: This flow shows where application logic ends and messaging infrastructure begins. - Message contents and kinds: Describe a message’s header and body, and distinguish documents, events, commands, and replies.
Why it matters: The distinction helps you tell what a message carries from what it asks or announces. - Channel delivery semantics: Distinguish point-to-point from publish-subscribe channels by who receives each message and the interaction style each supports.
Why it matters: Channel choice determines whether one consumer or every subscriber receives a message. - Channel implementation options: Explain how a message broker implements channels and identify the brokerless alternatives described here.
Why it matters: A channel describes how services communicate without requiring one particular messaging technology. - Asynchronous messaging advantages: Explain how asynchronous messaging reduces availability and location dependencies, buffers work, and makes remote communication explicit.
Why it matters: These advantages explain why services might communicate asynchronously instead of relying on synchronous calls. - Messaging infrastructure drawbacks: Describe the broker-related performance, availability, and operational costs of asynchronous messaging.
Why it matters: The benefits of messaging must be weighed against the infrastructure it adds.
Key terms: sender, receiver, message channel, sending port, message sender adapter, message handler adapter, header, message body, document, event
8.3.2 Implementing the interaction styles using messaging
This section shows how messaging implements four service interaction styles using message channels, replies, and correlation IDs.
- Messaging request and response: Explain how asynchronous request/response works with messaging and how it differs from request/response that expects an immediate reply.
Why it matters: The reply channel and correlation ID make a two-message exchange usable as a request and its response. - One-way message notifications: Describe how a client sends a one-way notification to a service.
Why it matters: Not every command message requires a response from the receiving service. - Publish-subscribe event channels: Explain how publish/subscribe messaging delivers domain events to interested services.
Why it matters: A single published event can reach multiple interested services without a separate request to each one. - Published requests with asynchronous replies: Trace how publish/async responses combines publication with reply matching.
Why it matters: This style lets a published request collect identifiable replies from consumers.
Key terms: asynchronous request/response, command message, reply channel header, correlation id, message identifier, one-way notifications, point-to-point channel, publish/subscribe, domain events, publish-subscribe channel
8.3.3 Designing an asynchronous messaging architecture
This section explains how to design message channels by defining their requirements first, then choosing a broker whose channel model and trade-offs fit.
- Requirements-first broker selection: Explain the two-step approach: define each message channel’s requirements, then choose messaging technology that supports them, rather than starting with a particular broker.
Why it matters: Starting with requirements helps you avoid committing to a broker before checking whether it fits the channel. - Message channel requirements: Describe the kinds of requirements to establish for each channel, including channel type, delivery and ordering, competing consumers, persistence, durability, scalability, and latency. Distinguish surviving a broker crash from retaining messages for a disconnected consumer.
Why it matters: These questions turn a vague need for messaging into criteria for selecting a channel implementation. - Broker-specific channel models: Explain that a message channel is an abstraction implemented differently by brokers, using examples such as ActiveMQ queues and topics, RabbitMQ exchanges and queues, Kafka topics, or Kinesis streams.
Why it matters: A channel design must be translated into the constructs the selected broker actually provides. - Broker capability trade-offs: Describe how brokers differ in delivery guarantees, ordering, persistence, durability, scalability, and latency, and explain why the choice depends on the channel’s requirements rather than a universally best broker.
Why it matters: Recognizing these trade-offs helps you match a broker to the reliability and performance a collaboration needs.
Key terms: message channel, messaging technology, technology-agnostic, channel type, delivery guarantees, message ordering, competing consumers, persistence, durability, queues
8.3.4 Evolving an asynchronous API
Explains how persistent messages affect asynchronous API compatibility and how to evolve event and command/reply APIs without breaking consumers.
- Message longevity and compatibility: Explain why evolving an asynchronous API requires compatibility with older messages, not just currently running services.
Why it matters: Message longevity is the reason apparently simple API changes need extra care. - Added event attribute compatibility: Describe what consumers must handle when an attribute is added to an event, including the default-value difference between JSON or ProtoBuf and AVRO.
Why it matters: Adding a field must work in both directions: with old consumers and with old stored events. - Event type replacement transition: Explain how dual publishing lets an event type be replaced without immediately breaking existing consumers, and why older events may still matter afterward.
Why it matters: A staged transition avoids forcing every event consumer to change at once. - Command reply API changes: Distinguish non-breaking from breaking changes to asynchronous command/reply APIs and describe how breaking versions can coexist.
Why it matters: Classifying a command/reply change determines whether both API versions must be available.
Key terms: persistent, message channels, older versions, event, attribute, default value, JSON, ProtoBuf, AVRO, dual publishing
8.3.5 AsyncAPI - an IDL for messaging-based APIs
This section explains how AsyncAPI describes a service’s asynchronous messaging contract and how tools can generate, validate, and use that description.
- Asynchronous API contract scope: Explain why a messaging API contract must describe both message structure and how messages flow between a service and its channels. State that AsyncAPI is a machine-readable IDL for asynchronous messaging APIs, not only event APIs.
Why it matters: A message schema alone does not tell another service where messages go or whether this service sends or receives them. - AsyncAPI document building blocks: Describe the roles of channels, messages, and operations in an AsyncAPI document, including what message schemas and send or receive operations specify.
Why it matters: These three objects let you read a specification as a description of what travels where and what the service does. - Customer event specification example: Trace how the CustomerCreatedEvent example connects its channel, message definition, payload schema, and send operation, and distinguish the corresponding consumer operation.
Why it matters: The example shows how the document’s separate definitions combine into a concrete publisher contract. - AsyncAPI tooling uses: Describe how Springwolf and asyncapi/cli help create or use AsyncAPI documents, distinguishing automatic document generation from validation and code or documentation generation.
Why it matters: Tooling makes the machine-readable contract useful for more than manual documentation.
Key terms: AsyncAPI, IDL, messaging APIs, machine-readable contract, channels, messages, operations, headers schema, payload schema, CustomerCreatedEvent
8.3.6 Pattern: Ordered competing receivers
This section explains how sharded message channels let multiple receivers increase throughput while preserving the order of messages for a particular entity.
- Concurrent receiver ordering risk: Explain why processing messages concurrently across service instances or threads can cause messages sent in order to be processed out of order.
Why it matters: The ordering risk explains why simply adding receivers is not enough. - Shard keyed receiver assignment: Describe how sharded channels, a message’s shard key, and assignment of each shard to one receiver preserve ordering while allowing multiple receivers to work.
Why it matters: Shard assignment makes it possible to scale receivers without scrambling the events for one order.
Key terms: message receivers, message ordering, point-to-point channel, sharded (partitioned) channels, shard key, consumer group, orderId
8.3.7 Pattern: Idempotent consumer pattern
This section explains why messaging consumers receive duplicates and how idempotent handlers or message-ID tracking prevent duplicate effects.
- At-least-once delivery and duplicates: Explain why brokers commonly provide at-least-once delivery and how a message can be delivered again after it has been processed.
Why it matters: A consumer must be prepared for redelivery even when its first attempt changed the database successfully. - Idempotent handlers and ordering: Distinguish when repeated execution of a handler is harmless from when it needs duplicate detection, and explain why redelivery order matters.
Why it matters: A handler is not safe from duplicate-related bugs merely because one operation can be repeated without an additional effect. - Transactional message ID tracking: Describe how a consumer uses processed message IDs to discard duplicates, including where it can store those IDs.
Why it matters: Message-ID tracking prevents a redelivered message from repeating a consequential action such as credit-card authorization.
Key terms: at-least-once delivery, exactly-once delivery, acknowledging, duplicate messages, idempotent, message handler, ordering, redelivering messages, message id, PROCESSED_MESSAGES
8.3.8 Pattern: Transaction outbox
This section explains how the transactional outbox reliably records messages alongside database changes, then compares polling and transaction-log tailing for publishing those messages.
- Atomic database and message updates: Explain why a service must record a message atomically with the business-data change that requires it, and how the transactional outbox achieves this in a relational database.
Why it matters: The outbox lets a service reliably publish messages associated with committed business changes without relying on a distributed transaction. - NoSQL pending-message variant: Describe the analogous approach for some NoSQL databases and its stated difficulty.
Why it matters: The same record-the-message-with-the-change principle can apply without a relational OUTBOX table, although finding messages to publish becomes a concern. - Polling publisher workflow and limits: Trace how a polling MessageRelay publishes outbox messages and explain when polling becomes less attractive.
Why it matters: Polling is a straightforward way to deliver outbox messages, but its database-query cost can influence the choice of relay. - Transaction-log tailing relay: Explain how transaction-log tailing publishes recorded messages and contrast its tradeoff with polling.
Why it matters: Log tailing offers another way to relay committed messages when polling is costly or impractical.
Key terms: Transactional outbox pattern, OUTBOX table, MessageRelay, local ACID transaction, NoSQL databases, list of messages, pending events, Polling publisher pattern, destination message channel, Transaction log tailing pattern
8.3.9 Synchronously invoking an asynchronous implementation
This section explains when a synchronous HTTP endpoint can respond while the requested operation is carried out through asynchronous messages, and the trade-offs of each choice.
- Response After Processing Completes: Explain how the Order Service can wait for other services to finish processing before responding to POST /orders, and why that choice affects the endpoint’s latency and availability.
Why it matters: A final answer is convenient for the client, but waiting for it makes the HTTP endpoint depend on other services being available. - Response Before Asynchronous Validation: Describe how the Order Service can respond after starting message-based processing, and explain the resulting benefits and obligations for the client.
Why it matters: Responding early keeps the endpoint responsive when another service is temporarily unavailable, but shifts final-outcome tracking to the client.
Key terms: HTTP response, final outcome, runtime coupled, latency, availability, PENDING, order ID, partial outcome, runtime coupling, poll
8.3.10 Libraries and frameworks for messaging
This section explains why the book uses Eventuate for messaging and how its basic and higher-level APIs relate to messaging patterns.
- Higher-level messaging library rationale: Explain the drawbacks of using a message broker’s client library directly and why the examples use Eventuate instead.
Why it matters: It explains why the examples use a messaging framework rather than raw broker calls. - Basic messaging API behavior: Describe how Eventuate’s basic producer and consumer APIs send and receive messages, and identify the patterns each implements.
Why it matters: It connects the API calls to the transactional sending and duplicate-handling patterns underneath them. - Higher-level messaging APIs: Distinguish Eventuate’s domain-event and command messaging APIs and explain how they sit on top of basic messaging.
Why it matters: It helps the reader recognize whether an example is using basic messaging, domain events, or commands.
Key terms: message broker’s client library, higher-level library or framework, Eventuate platform, MessageProducer, MessageConsumer, Transaction outbox pattern, Eventuate CDC service, Idempotent consumer pattern, DomainEventPublisher, domain events
8.4 Summary
Where this is used later
- Using the Saga pattern (chapter 9) · Service collaboration for distributed operations depends on communication between services.
- (chapter intro) (chapter 9) · Introduces interprocess communication in a microservice architecture.
- Overview of saga coordination (chapter 9) · APIs and their service-level objectives.
- Resilient and performant API Composition (chapter 12) · Provides the reason API composition must account for slow or unavailable providers.
- ACID transactions in a microservice architecture (chapter 9) · Relates to the availability concerns of synchronous communication.
- Implementing the findOrder() system query using the API composition pattern (chapter 12) · Applies to an API-composed findOrder response assembled from service results.
- Implementing orchestration using asynchronous messaging (chapter 10) · Messaging interaction styles.
- The drawbacks of the CQRS pattern (chapter 13) · Events can be delivered through messaging channels.
Concepts explained in this chapter
- channelA communication path through which messages are sent and received.
- service discoveryService discovery is a mechanism that lets services find and communicate with service instances without hardcoded network locations.
- remote procedure callAn interaction style in which a client invokes an operation on a remote service through a call resembling a local method invocation.
- interface definition languageAn interface definition language is a formal language for specifying the operations, data structures, and communication contracts exposed by software interfaces.
- publish-subscribe patternA messaging channel that distributes each published message to subscribing consumers.
- OpenAPI specificationA standard for describing HTTP APIs, including their operations, parameters, and schemas, in a machine-readable format.
- api styleAn API style guide is an organization-wide set of conventions for designing, naming, documenting, securing, and evolving APIs.
- outbox patternA messaging pattern that atomically records an outgoing message alongside a business-data change in the same database transaction, then publishes the message afterward.
- point-to-point communicationA point-to-point channel delivers each message to exactly one consumer among those reading from the channel.
- command messageA message requesting that a receiver invoke a specified operation with specified parameters.
- rest apiAn HTTP-based application programming interface that exposes resources according to REST constraints.
- interprocess communicationInterprocess communication is the exchange of data or control between independently executing processes through mechanisms such as network calls or message passing.
- idempotent consumer patternA messaging pattern in which a consumer detects and discards duplicate messages so repeated delivery has the effect of processing a message once.
- asynchronous requestAn interaction style in which a requester sends a request and later receives a response without blocking for an immediate result.
- data transfer objectA data transfer object is a data structure that carries structured data across an interface without exposing domain implementation objects.
- circuit breaker patternA circuit breaker pattern stops calls to a failing dependency for a period and later permits test calls to determine whether it has recovered.
- messageA message is a structured unit of data transmitted between communicating software components, potentially containing headers and a payload.
- HTTP methodAn HTTP verb is a standardized request method indicating the intended operation on a resource.
- OpenAPI documentAn OpenAPI document is a machine-readable description of an API's endpoints, methods, parameters, representations, authentication, and metadata.
- RESTAn architectural style for networked systems defined by constraints on interactions between components and resources.
- REST maturity modelThe REST maturity model classifies HTTP APIs by their progression from a single endpoint toward resource orientation, HTTP verbs, and hypermedia controls.
- backward compatibilityThe property of allowing existing clients to continue interacting correctly with an API after a change.
- hypermediaHATEOAS is a REST constraint in which resource representations contain links that guide clients through available application actions.
- resourceA REST resource is a representation-addressable business object or collection of business objects exposed by an API.
- polling publisherA messaging pattern in which a separate process periodically queries a database outbox for unsent messages and publishes them.
- transaction log tailingA messaging pattern that publishes messages derived from changes read from a database transaction log.
- AsyncAPIAsyncAPI is a machine-readable specification for defining asynchronous messaging APIs, including channels, messages, operations, and message schemas.
- competing consumersCompeting consumers are multiple consumers that concurrently process messages from the same channel or consumer group.
- outbox tableAn outbox table is a persistent table that stores messages to be delivered reliably as part of an application's transaction.
- breaking changeA modification to an interface or behavior that can invalidate existing consumers or require them to change.
- side-by-side APIA side-by-side API is an API implementation that supports old and new contract versions concurrently during a transition.
- command/reply-based messagingAn interaction style in which one party sends a command and another party returns a reply describing the result.
- domain event publishingA messaging technique in which a service publishes events representing significant changes to domain entities or aggregates.
- schemaA formal definition of the fields, types, and structural rules of a message or data object.
- asynchronous communicationA messaging technique in which a sender continues processing without waiting for an immediate reply.
- service-level objectiveA target value for a service-level indicator that expresses a desired level of reliability or performance.
- protobufProtocol Buffers is a language-neutral, platform-neutral mechanism for serializing structured data using compact binary encoding and numeric field tags.
- message orderingThe sequencing constraint that messages are processed in the order established by their publication or channel position.
- application-level service discoveryApplication-level service discovery is service discovery implemented by application services and clients interacting with a dedicated service registry.
- client-side discoveryClient-side discovery is a service discovery pattern in which a client retrieves service instances from a registry and selects one for a request.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
