Inter-Process Communication

Interaction Styles

来自 Inter-Process Communication in a Microservices Architecture

When selecting an IPC mechanism for a service, it is useful to think first about how services interact. There are a variety of client⇔service interaction styles. They can be categorized along two dimensions. The first dimension is whether the interaction is one-to-one or one-to-many:

One-to-one – Each client request is processed by exactly one service instance.
One-to-many – Each request is processed by multiple service instances.

The second dimension is whether the interaction is synchronous or asynchronous:

Synchronous – The client expects a timely response from the service and might even block while it waits. Asynchronous – The client doesn’t block while waiting for a response, and the response, if any, isn’t necessarily sent immediately.

The following table shows the various interaction styles.

                   One-to-One                One-to-Many
    Synchronous    Request/response          —
    Asynchronous   Notification              Publish/subscribe
                   Request/async response    Publish/async responses

There are the following kinds of one-to-one interactions:

    - Request/response – A client makes a request to a service and waits for a response. The client expects the response to arrive in a timely fashion. In a thread-based application, the thread that makes the request might even block while waiting.
    - Notification (a.k.a. a one-way request) – A client sends a request to a service but no reply is expected or sent.
    - Request/async response – A client sends a request to a service, which replies asynchronously. The client does not block while waiting and is designed with the assumption that the response might not arrive for a while.

There are the following kinds of one-to-many interactions:

    - Publish/subscribe – A client publishes a notification message, which is consumed by zero or more interested services.
    - Publish/async responses – A client publishes a request message, and then waits a certain amount of time for responses from interested services.