liveBook · Manning

Asynchronous communication

As explained in Microservices Patterns, Second Edition

A messaging technique in which a sender continues processing without waiting for an immediate reply.

Asynchronous communication lets a sender continue without waiting for an immediate reply. Messaging can reduce runtime coupling between services: a sender need not wait for a temporarily unavailable receiver to respond. The operation’s final result may arrive later, so callers must be able to tolerate that delay. section 8.3 section 8.3.1

Messages travel through channels, which can be implemented with a broker or a brokerless technology. Sender and receiver adapters connect the messaging infrastructure to business logic through ports. A broker can buffer work during demand spikes or while consumers are slow. section 8.3 section 8.3.1

Messaging supports several interaction styles:

  • Asynchronous request/reply: send a request and continue; a reply arrives later. section 8.3
  • One-way notification: send a message without expecting a reply. section 8.3
  • Publish/subscribe: publish an event for one or more consumers. section 8.3

Creating an order

The Order Service handles POST /orders by sending a validation message to the Customer Service and immediately returning an HTTP response. The customer service later replies, allowing the order service to approve or reject the order. Separately, an Order Created event can let notification handling send a confirmation email without making delivery part of order creation. section 4.4.3 section 6.2.4

Figure 4.15 The Order Service handles the POST /orders request by sending a message to the Customer Service to validate the customer and returning an HTTP response immediately. Eventually, the Customer Service sends a message to the Order Service, which can then either approve or reject the Order
runtime uncoupled async

Follow the immediate HTTP response and the later validation reply in the order flow. section 4.4.3

Choose messaging when delayed completion or decoupled notification is acceptable and reduced runtime coupling is valuable. It also introduces design decisions: choose broker-based or brokerless infrastructure, consider ordering and duplicate messages, and integrate message sending and receiving with database transactions. Sagas can use messaging to coordinate local transactions, but may need compensating transactions and application-level consistency techniques. section 8.3 section 9.2

Messaging is not the only way to reduce runtime coupling. An operation can instead be made local by merging services or moving responsibilities between them. Merging can produce an overly large service, while moving responsibilities can make other operations span services. Within a monolith, a direct method call is simpler, though it couples the calling module to its dependencies. section 4.4.3 section 6.2.4

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines interaction styles and message-channel structure, then identifies broker selection, ordering, duplicate detection, and transactional messaging as implementation concerns.
Examples
Illustrates order validation with a later reply, order-created notification delivery, and webhooks for CI/CD branch changes.
What you can do after
Evaluate messaging against direct invocation and service restructuring using coupling, delayed completion, buffering, and implementation concerns.
How it connects
Connects messaging with runtime coupling, publish/subscribe, sagas, and database transactions.

Also explained in

Compare how 2 books explain asynchronous communication →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.