Skip to content

Test ebook #3477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e9e4174
Important updates in regards Microservice architecture patterns and s…
CESARDELATORRE Oct 14, 2017
93509bc
added redirect
mairaw Oct 14, 2017
22a2e29
Merge remote-tracking branch 'upstream/master'
CESARDELATORRE Oct 17, 2017
eb90d9e
Important updates in regards Microservice architecture patterns and s…
CESARDELATORRE Oct 14, 2017
1a79dc6
added redirect
mairaw Oct 14, 2017
89d11fc
Revert so PR is not mixing multiple eBooks
CESARDELATORRE Oct 17, 2017
8784557
Merge branch 'master' of https://github.com/dotnet-architecture/docs
CESARDELATORRE Oct 17, 2017
b734286
Update orchestrate-high-scalability-availability.md
CESARDELATORRE Oct 17, 2017
3f6e849
Updates on .NET Core 2.0 and news in Docker in chapters related to Do…
CESARDELATORRE Oct 17, 2017
d384fc0
Merge branch 'master' of https://github.com/dotnet-architecture/docs
CESARDELATORRE Oct 17, 2017
b657e0f
Updates in State and Data in Docker apps
CESARDELATORRE Oct 17, 2017
448020d
Minor changes in Architecture chapter/section
CESARDELATORRE Oct 17, 2017
a8c0af5
Updates for the Docker development process chapter
CESARDELATORRE Oct 18, 2017
a557885
Updates based on Maira's feedback.
CESARDELATORRE Oct 18, 2017
d0afff4
Update in Design and Implementation of Microservices
CESARDELATORRE Oct 19, 2017
cfb9d0a
Updates based on Bill's feedback
CESARDELATORRE Oct 19, 2017
def7adf
Important updates in regards Microservice architecture patterns and s…
CESARDELATORRE Oct 14, 2017
f6ab8f3
added redirect
mairaw Oct 14, 2017
729ad74
Revert so PR is not mixing multiple eBooks
CESARDELATORRE Oct 17, 2017
b30fa47
commit due to rebase
CESARDELATORRE Oct 20, 2017
6ed4b0f
Updates in State and Data in Docker apps
CESARDELATORRE Oct 17, 2017
460f991
Minor changes in Architecture chapter/section
CESARDELATORRE Oct 17, 2017
565dd1b
Updates for the Docker development process chapter
CESARDELATORRE Oct 18, 2017
5c99f77
Updates based on Maira's feedback.
CESARDELATORRE Oct 18, 2017
48eec97
Update in Design and Implementation of Microservices
CESARDELATORRE Oct 19, 2017
3aa5726
Updates based on Bill's feedback
CESARDELATORRE Oct 19, 2017
b009eb7
Merge branch 'master' of https://github.com/dotnet-architecture/docs
CESARDELATORRE Oct 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .openpublishing.redirection.json
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,11 @@
"redirect_url": "/dotnet/standard/net-standard",
"redirect_document_id": true
},
{
"source_path": "docs/standard/microservices-architecture/architect-microservice-container-applications/communication-between-microservices.md",
"redirect_url": "/dotnet/standard/microservices-architecture/architect-microservice-container-applications/communication-in-microservice-architecture",
"redirect_document_id": true
},
{
"source_path": "docs/standard/serialization/marshal-by-value.md",
"redirect_url": "/dotnet/standard/serialization-concepts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ There are two kinds of asynchronous messaging communication: single receiver mes

Message-based asynchronous communication with a single receiver means there is point-to-point communication that delivers a message to exactly one of the consumers that is reading from the channel, and that the message is processed just once. However, there are special situations. For instance, in a cloud system that tries to automatically recover from failures, the same message could be sent multiple times. Due to network or other failures, the client has to be able to retry sending messages, and the server has to implement an operation to be idempotent in order to process a particular message just once.

Single-receiver message-based communication is especially well suited for sending asynchronous commands from one microservice to another as shown in Figure 4-17 that illustrates this approach.
Single-receiver message-based communication is especially well suited for sending asynchronous commands from one microservice to another as shown in Figure 4-18 that illustrates this approach.

Once you start sending message-based communication (either with commands or events), you should avoid mixing message-based communication with synchronous HTTP communication.

![](./media/image17.PNG)
![](./media/image18.PNG)

**Figure 4-17**. A single microservice receiving an asynchronous message
**Figure 4-18**. A single microservice receiving an asynchronous message

Note that when the commands come from client applications, they can be implemented as HTTP synchronous commands. You should use message-based commands when you need higher scalability or when you are already in a message-based business process.

Expand All @@ -51,11 +51,11 @@ If a system uses eventual consistency driven by integration events, it is recomm

As noted earlier in the [Challenges and solutions for distributed data management](#challenges-and-solutions-for-distributed-data-management) section, you can use integration events to implement business tasks that span multiple microservices. Thus you will have eventual consistency between those services. An eventually consistent transaction is made up of a collection of distributed actions. At each action, the related microservice updates a domain entity and publishes another integration event that raises the next action within the same end-to-end business task.

An important point is that you might want to communicate to multiple microservices that are subscribed to the same event. To do so, you can use publish/subscribe messaging based on event-driven communication, as shown in Figure 4-18. This publish/subscribe mechanism is not exclusive to the microservice architecture. It is similar to the way [Bounded Contexts](http://martinfowler.com/bliki/BoundedContext.html) in DDD should communicate, or to the way you propagate updates from the write database to the read database in the [Command and Query Responsibility Segregation (CQRS)](http://martinfowler.com/bliki/CQRS.html) architecture pattern. The goal is to have eventual consistency between multiple data sources across your distributed system.
An important point is that you might want to communicate to multiple microservices that are subscribed to the same event. To do so, you can use publish/subscribe messaging based on event-driven communication, as shown in Figure 4-19. This publish/subscribe mechanism is not exclusive to the microservice architecture. It is similar to the way [Bounded Contexts](http://martinfowler.com/bliki/BoundedContext.html) in DDD should communicate, or to the way you propagate updates from the write database to the read database in the [Command and Query Responsibility Segregation (CQRS)](http://martinfowler.com/bliki/CQRS.html) architecture pattern. The goal is to have eventual consistency between multiple data sources across your distributed system.

![](./media/image18.png)
![](./media/image19.png)

**Figure 4-18**. Asynchronous event-driven message communication
**Figure 4-19**. Asynchronous event-driven message communication

Your implementation will determine what protocol to use for event-driven, message-based communications. [AMQP](https://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol) can help achieve reliable queued communication.

Expand Down Expand Up @@ -106,5 +106,5 @@ Additional topics to consider when using asynchronous communication are message


>[!div class="step-by-step"]
[Previous] (communication-between-microservices.md)
[Previous] (communication-in-microservice-architecture.md)
[Next] (maintain-microservice-apis.md)
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
title: Communication between microservices
description: .NET Microservices Architecture for Containerized .NET Applications | Communication between microservices
keywords: Docker, Microservices, ASP.NET, Container
title: Communication in a microservice architecture
description: .NET Microservices Architecture for Containerized .NET Applications | Communication in a microservice architecture architectures
keywords: Docker, Microservices, ASP.NET, Container
author: CESARDELATORRE
ms.author: wiwagn
ms.date: 05/26/2017
ms.date: 10/18/2017
ms.prod: .net-core
ms.technology: dotnet-docker
ms.topic: article
---
# Communication between microservices
# Communication in a microservice architecture

In a monolithic application running on a single process, components invoke one another using language-level method or function calls. These can be strongly coupled if you are creating objects with code (for example, new ClassName()), or can be invoked in a decoupled way if you are using Dependency Injection by referencing abstractions rather than concrete object instances. Either way, the objects are running within the same process. The biggest challenge when changing from a monolithic application to a microservices-based application lies in changing the communication mechanism. A direct conversion from in-process method calls into RPC calls to services will cause a chatty and not efficient communication that will not perform well in distributed environments. The challenges of designing distributed system properly are well enough known that there is even a canon known as the [The fallacies of distributed computing](https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing) that lists assumptions that developers often make when moving from monolithic to distributed designs.
In a monolithic application running on a single process, components invoke one another using language-level method or function calls. These can be strongly coupled if you are creating objects with code (for example, `new ClassName()`), or can be invoked in a decoupled way if you are using Dependency Injection by referencing abstractions rather than concrete object instances. Either way, the objects are running within the same process. The biggest challenge when changing from a monolithic application to a microservices-based application lies in changing the communication mechanism. A direct conversion from in-process method calls into RPC calls to services will cause a chatty and not efficient communication that will not perform well in distributed environments. The challenges of designing distributed system properly are well enough known that there is even a canon known as the [The fallacies of distributed computing](https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing) that lists assumptions that developers often make when moving from monolithic to distributed designs.

There is not one solution, but several. One solution involves isolating the business microservices as much as possible. You then use asynchronous communication between the internal microservices and replace fine-grained communication that is typical in intra-process communication between objects with coarser-grained communication. You can do this by grouping calls, and by returning data that aggregates the results of multiple internal calls, to the client.

Expand Down Expand Up @@ -41,13 +41,19 @@ A microservice-based application will often use a combination of these communica

These axes are good to know so you have clarity on the possible communication mechanisms, but they are not the important concerns when building microservices. The asynchronous nature of client thread execution not even the asynchronous nature of the selected protocol are the important points when integrating microservices. What *is* important is being able to integrate your microservices asynchronously while maintaining the independence of microservices, as explained in the following section.

## Asynchronous microservice integration enforce microservice’s autonomy
## Asynchronous microservice integration enforces microservice’s autonomy

As mentioned, the important point when building a microservices-based application is the way you integrate your microservices. Ideally, you should try to minimize the communication between the internal microservices. The less communications between microservices, the better. But of course, in many cases you will have to somehow integrate the microservices. When you need to do that, the critical rule here is that the communication between the microservices should be asynchronous. That does not mean that you have to use a specific protocol (for example, asynchronous messaging versus synchronous HTTP). It just means that the communication between microservices should be done only by propagating data asynchronously, but try not to depend on other internal microservices as part of the initial service’s HTTP request/response operation.

If possible, never depend on synchronous communication (request/response) between multiple microservices, not even for queries. The goal of each microservice is to be autonomous and available to the client consumer, even if the other services that are part of the end-to-end application are down or unhealthy. If you think you need to make a call from one microservice to other microservices (like performing an HTTP request for a data query) in order to be able to provide a response to a client application, you have an architecture that will not be resilient when some microservices fail.

Moreover, having dependencies between microservices (like performing HTTP requests between them for querying data) not only makes your microservices not autonomous. In addition, their performance will be impacted. The more you add synchronous dependencies (like query requests) between microservices, the worse the overall response time will get for the client apps.
Moreover, having HTTP dependencies between microservices, like when creating long request/response cycles with HTTP request chains, as shown in the first part of the Figure 4-15, not only makes your microservices not autonomous but also their performance is impacted as soon as one of the services in that chain is not performing well.

The more you add synchronous dependencies between microservices, such as query requests, the worse the overall response time gets for the client apps.

![](./media/image15.png)

**Figure 4-15**. Anti-patterns and patterns in communication between microservices

If your microservice needs to raise an additional action in another microservice, if possible, do not perform that action synchronously and as part of the original microservice request and reply operation. Instead, do it asynchronously (using asynchronous messaging or integration events, queues, etc.). But, as much as possible, do not invoke the action synchronously as part of the original synchronous request and reply operation.

Expand All @@ -67,11 +73,11 @@ There are also multiple message formats like JSON or XML, or even binary formats

### Request/response communication with HTTP and REST

When a client uses request/response communication, it sends a request to a service, then the service processes the request and sends back a response. Request/response communication is especially well suited for querying data for a real-time UI (a live user interface) from client apps. Therefore, in a microservice architecture you will probably use this communication mechanism for most queries, as shown in Figure 4-15.
When a client uses request/response communication, it sends a request to a service, then the service processes the request and sends back a response. Request/response communication is especially well suited for querying data for a real-time UI (a live user interface) from client apps. Therefore, in a microservice architecture you will probably use this communication mechanism for most queries, as shown in Figure 4-16.

![](./media/image15.png)
![](./media/image16.png)

**Figure 4-15**. Using HTTP request/response communication (synchronous or asynchronous)
**Figure 4-16**. Using HTTP request/response communication (synchronous or asynchronous)

When a client uses request/response communication, it assumes that the response will arrive in a short time, typically less than a second, or a few seconds at most. For delayed responses, you need to implement asynchronous communication based on [messaging patterns](https://docs.microsoft.com/azure/architecture/patterns/category/messaging) and [messaging technologies](https://en.wikipedia.org/wiki/Message-oriented_middleware), which is a different approach that we explain in the next section.

Expand All @@ -91,15 +97,15 @@ There is additional value when using HTTP REST services as your interface defini

Another possibility (usually for different purposes than REST) is a real-time and one-to-many communication with higher-level frameworks such as [ASP.NET SignalR](https://www.asp.net/signalr) and protocols such as [WebSockets](https://en.wikipedia.org/wiki/WebSocket).

As Figure 4-16 shows, real-time HTTP communication means that you can have server code pushing content to connected clients as the data becomes available, rather than having the server wait for a client to request new data.
As Figure 4-17 shows, real-time HTTP communication means that you can have server code pushing content to connected clients as the data becomes available, rather than having the server wait for a client to request new data.

![](./media/image16.png)
![](./media/image17.png)

**Figure 4-16**. One-to-one real-time asynchronous message communication
**Figure 4-17**. One-to-one real-time asynchronous message communication

Since communication is in real time, client apps show the changes almost instantly. This is usually handled by a protocol such as WebSockets, using many WebSockets connections (one per client). A typical example is when a service communicates a change in the score of a sports game to many client web apps simultaneously.


>[!div class="step-by-step"]
[Previous] (identify-microservice-domain-model-boundaries.md)
[Previous] (direct-client-to-microservice-communication-versus-the-api-gateway-pattern.md)
[Next] (asynchronous-message-based-communication.md)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ An important rule for microservices architecture is that each microservice must

This means that the conceptual model of the domain will differ between subsystems or microservices. Consider enterprise applications, where customer relationship management (CRM) applications, transactional purchase subsystems, and customer support subsystems each call on unique customer entity attributes and data, and where each employs a different Bounded Context (BC).

This principle is similar in [domain-driven design (DDD)](https://en.wikipedia.org/wiki/Domain-driven_design), where each [Bounded Context](https://martinfowler.com/bliki/BoundedContext.html) or autonomous subsystem or service must own its domain model (data plus logic and behavior). Each DDD Bounded Context correlates to one business microservice (one or several services). (We expand on this point about the Bounded Context pattern in the next section.)
This principle is similar in [Domain-driven design (DDD)](https://en.wikipedia.org/wiki/Domain-driven_design), where each [Bounded Context](https://martinfowler.com/bliki/BoundedContext.html) or autonomous subsystem or service must own its domain model (data plus logic and behavior). Each DDD Bounded Context correlates to one business microservice (one or several services). (We expand on this point about the Bounded Context pattern in the next section.)

On the other hand, the traditional (monolithic data) approach used in many applications is to have a single centralized database or just a few databases. This is often a normalized SQL database that is used for the whole application and all its internal subsystems, as shown in Figure 4-7.

Expand Down
Loading