Asynchronous Messaging

Another useful approach for inter-service communications in distributed systems is asynchronous messaging. Using an asynchronous messaging approach, the client makes a request by sending a message. The client can then continue doing other things, and if the service is expected to send a response it does this by sending another message back. The client will generally wait for acknowledgment that the message was received and queued, but will not have to wait for the request to be processed with a response. In some cases the client does not need a response or will check back with a service at a later time on the status of the request.

There are a number of benefits to asynchronous messaging, but also some trade-offs and challenges that need to be considered. A great introduction to asynchronous messaging is available here from the Microsoft Patterns and Practices team at https://msdn.microsoft.com/en-us/library/dn589781.aspx. This material is a great primer to help those new to asynchronous messaging concepts.

As we mentioned previously, when designing an application using a microservices approach, there are a number of things to consider with regard to communication style, protocols, and serialization formats used.

Considerations with inter-service communications:

Select a communication approach that is best suited for the interaction, and if possible use asynchronous messaging.

Consider protocol and serialization formats and the various trade-offs. Performance is important, but so is interoperability, flexibility, and ease of use.

Always consider how coupling is affected by any decision, because as our services become coupled we tend to lose many of the benefits of a microservices architecture.

Always consider caching when making requests on external systems.

Always implement the resiliency patterns covered in Chapter 1 in the Best Practices subsection when calling other services.

When one service takes a dependency on another service, it should not require the dependent service to be available at deployment or impact its ability to start. There should never be a need to deploy and start services in a specific order.

Consider alternate approaches to reduce overhead. For example, if one service uses information received in a request to call another with additional information there might be no need to reserialize the original message. The original message can be passed with the additional information in the header.

There’s a place for both synchronous request/response and asynchronous messaging in today’s systems. We really just touched the surface on some inter-service communications concepts in this section. For more information on routing requests to services see the Service Discovery section in Chapter 5. Inter-service communication is an important consideration when designing an application based on microservices architecture.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.86.18