Chapter 2, Communication Patterns Flashcards

1
Q

What is synchronous communication in microservices?

A

In synchronous communication, one microservice invokes another microservice and expects a response within a given time frame. Patterns used include Request-Response and Remote Procedure Calls (RPC).
Page 48

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do microservices communicate asynchronously?

A

In asynchronous communication, microservices communicate by passing messages asynchronously with the help of an intermediary (known as a message broker), using patterns such as queue-based messaging and publisher-subscriber messaging.
Page 48

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which communication pattern is most commonly used in cloud native applications?

A

The Request-Response pattern is probably the most commonly used communication pattern in cloud native applications and distributed computing at large.
Page 49

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does the Request-Response pattern work in cloud native applications?

A

The Request-Response pattern establishes a connection between the client and the server application (microservice) to exchange data synchronously. The client sends a request for data and waits for a response or until a time-out occurs. This style is sometimes referred to as query-based interaction.
Page 50

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why is the Request-Response pattern popular for building cloud native applications?

A

It is often used for building interactive business logic that requires immediate responses and is agnostic of underlying network protocols and data formats. HTTP and RESTful services are common realizations of this pattern.
Page 50

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is RPC and when is it recommended?

A

RPC is an efficient and robust way to build synchronous communication among microservices. Cloud native RPC technologies such as gRPC are recommended, but RPC may not be the best choice for services exposed to external consumers like web and mobile applications.
Page 56

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does asynchronous communication work among microservices?

A

One microservice sends data as messages without expecting a response. Communication is facilitated by a message broker, which receives messages from the producer and sends them to the consumer.
Page 58

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the Multiple-Receiver or Publisher-Subscriber pattern in asynchronous messaging?

A

This pattern is used when the same message needs to be sent to multiple consumers interested in a particular event. It is often used in cloud native applications for microservices that need to execute business logic or notify other services upon certain events.
Page 63

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the role of the event bus in the Publisher-Subscriber pattern?

A

The event bus handles publisher and subscription requests and delivers messages to corresponding subscribers.
Page 64

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the Asynchronous Request-Reply pattern?

A

This pattern is used when producers need to send messages to a consumer via a broker and receive a reply from the consumer via the broker on a different channel.
Page 66

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How is the Asynchronous Request-Reply pattern used in practice?

A

It is not an alternative to the Request-Response pattern but serves a specific purpose when a reply containing business data is needed. Messaging solutions like RabbitMQ, ActiveMQ, and Azure Service Bus support this pattern.
Page 67

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What should be considered when using the Asynchronous Request-Reply pattern?

A

Although it might seem more reliable than synchronous messaging, the performance implications due to using queues and correlating messages must be considered. This pattern is less frequently used than other asynchronous patterns.
Page 68

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a key aspect of building communication among cloud native applications?

A

One of the most important aspects is the service definition, which defines the microservice interface to its consumers and can differ based on the communication protocol used.
Page 69

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How are service definitions used in synchronous communication?

A

Service definitions are published to a central service registry, a metadata repository that other microservices and developers can interact with. The registry should handle various service definitions such as OpenAPI, gRPC, and GraphQL schemas.
Page 70

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How does having a service definition impact the microservice development life cycle?

A

It changes the development life cycle as you can code-generate or validate the microservice implementation against the service definition, ensuring compliance with the advertised definition.
Page 72

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How are service definition patterns related to other patterns?

A

They are closely related to the Service Registry and Discovery pattern, the synchronous Request-Response and RPC patterns, and the API management patterns.
Page 73

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How are service definitions used in asynchronous communication?

A

Messages exchanged between producers and consumers contain structured data serialized/deserialized using a schema defining the data. Producers and consumers use a central metadata registry to store these schemas.

Page 73

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Why are schemas important in asynchronous messaging?

A

Schemas ensure reliable communication by validating data exchanged between producers and consumers, avoiding inconsistencies and data mismatches.
Page 77

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are RESTful services and how do they work?

A

RESTful services build microservices using the Request-Response pattern, representing objects and services over a network as resources. Clients access resources via unique URIs and standard HTTP operations (GET, PUT, DELETE, POST, HEAD).
Page 79

20
Q

How does GraphQL compare to REST?

A

GraphQL allows fetching exact data needed in a single request, avoiding over-fetching or under-fetching. It offers advantages like validation, type checking, detailed error handling, and backward-compatible versioning.
Page 82

21
Q

What is the WebSocket protocol and how is it used?

A

WebSocket is a technology for implementing synchronous Request-Response patterns, supporting full duplex and asynchronous messaging. It uses a single TCP connection for bidirectional traffic and an initial HTTP handshake.

Page 83

22
Q

How does the Request-Response Pattern work?

A

In the Request-Response pattern (Figure 2-1), one microservice (which acts as the client) sends a request and waits for a response from one or more other microservices or systems. The business logic of the client application blocks until it receives the response, and the communication channel has to be kept open until the response is received by the client application.

49

23
Q

Which patterns is The Request-Response communication pattern commonly used with?

A

Service Orchestration and API Gateway
These patterns heavily use the request-response style of communication when building the composition of services and exposing services as managed APIs, respectively.

Request-Reply
This pattern uses an intermediary to implement a similar style of communication with the use of a queue.

51

24
Q

Describe Remote Procedure Calls Pattern

A

The Remote Procedure Calls (RPC) pattern is a synchronous communication pattern that enables distributed applications to invoke procedures of a remote application—just as if making a local procedure call. A given microservice can build a certain piece of business logic as a function and make it available for remote invocation by a consumer that resides in a separate process.

52

25
Q

What are some of the patterns that are related to Remote Procedure Calls?

A

Service composition and API management patterns
RPC is commonly used as a foundational pattern when realizing these other patterns (covered in Chapters 3 and 7, respectively).
Request-Response

This is an alternative approach for RPC.

57

26
Q

When to use The Request-Response Pattern?

A

Services need real-time responses.
Service contracts need to be flexible.
To interoperate with many types of consumers.
Services are exposed to external consumers.

57

27
Q

When not to use The Request-Response Pattern?

A

Low-latency and high-throughput communication is required.
Strict contract-first interactions are required.

57

28
Q

What are the benefits of The Request-Response Pattern?

A

The most interoperable and standard communication pattern for implementing services exposed to external as well as internal consumers.

57

29
Q

When to use The Remote Procedure Calls Pattern?

A

High-performance communication among services is critical.
To enforce a strict contract-first approach for building services.
Service business logic needs to be completely independent from the underlying wire protocol and its semantics.

57

30
Q

When not to use The Remote Procedure Calls Pattern?

A

Service interoperability with multiple application types such as web or mobile apps is required.
You have to enable loose contracts and flexibility for consumers.

57

31
Q

What are the benefits of The Remote Procedure Calls Pattern?

A

Suitable for efficient and type-safe service-to-service communication.

57

32
Q

Describe the Single-Receiver Pattern

A

In the Single-Receiver pattern, a given microservice delivers messages to exactly one target microservice, or to a system using a messaging infrastructure such as a message broker. The messages sent here are usually considered commands because the pattern ensures that the messages are delivered to a single consumer that is supposed to process them and perform an action.
For example, when we have to process an order in an online retail system, we place an asynchronous message in a message broker queue, so that the Order-Processing service can process it and perform actions. Since it describes the information exchange between one producer and a single receiver, this pattern is also called point-to-point asynchronous messaging.

59

33
Q

How does the Single-Receiver Pattern work?

A

The Single-Receiver pattern is built by publishing messages to a queue in the message broker. One consumer service or system then consumes messages from that queue. The producer service is interested only in whether the message is delivered successfully to the queue; it doesn’t care when or whether the message is processed.

60

34
Q

How does the Multiple-Receiver Pattern work?

A

In the Multiple-Receiver pattern, messages are delivered to more than one consumer microservice. We also use a message broker or an event bus to facilitate the asynchronous message delivery. One microservice publishes a message to a topic in the event bus, and one or more microservices can subscribe to a given topic. The message is asynchronously delivered to all the subscribers of that topic.
The Multiple-Receiver pattern is implemented using an event bus (Figure 2-5)
The event bus is responsible for handling the publisher and subscription requests and delivering the message to the corresponding subscribers.

63

35
Q

How does Asynchronous Request-Reply Pattern work?

A

In the Asynchronous Request-Reply pattern, we follow the same messaging model used in the Single-Receiver pattern: the producer microservice publishes messages to a queue in a message broker, and then the producer consumes that message from the queue. However, the message contains metadata specifying that it requires a reply, the location where the reply should be sent, and how to correlate the reply. The producer uses that information to send the reply back to the producer via a completely different channel established through a separate queue in the message broker.

66

36
Q

When to use Single-Receiver Patten?

A

One microservice sends an asynchronous command to another microservice.
For ordered message delivery.
For guaranteed message delivery.

69

37
Q

When not to use Single-Receiver Patten?

A

Efficient data transfer is required without delivery semantics such as at-least-once.

69

38
Q

When to use Multiple-Receiver Patten?

A

More than one consumer is interested in the same message/event.

69

39
Q

When not to use Multiple-Receiver Patten?

A

Usually not suitable when you need guaranteed message delivery.

69

40
Q

When to use Asynchronous Request-Reply Patten?

A

For asynchronous messaging scenarios in which correlation is required between a request and a reply.

69

41
Q

When not to use Asynchronous Request-Reply Patten?

A

Shouldn’t be used as a reliable messaging alternative to synchronous request-response patterns.

69

42
Q

How does The service definition work?

A

The service definition is a way of declaring how a given service can be consumed by consumers/clients. It is something that will be shared with consumers prior to establishing the communication channel among the services where synchronous communication takes place.
As illustrated in Figure 2-7, microservices can publish their service definitions to a service registry (or they can be published manually by the microservice owners). Then the consumers of those microservices can connect to the service registry and obtain the service definitions (programmatically or manually by the developers). This step is known as service discovery.

70

43
Q

When to use RESTful services?

A

The business use case fits the resource-oriented model (in which you can represent business entities and functionalities as HTTP resources and operations).
The service needs to interoperate with disparate sets of clients (web clients, mobile clients).
The service needs to negotiate to support various content types (JSON, CSV, XML) based on client requests.
You need human-readable text-based message formats.

86

44
Q

When to use GraphQL?

A

Clients want to determine the data they want, how they want it, and the data format.
You want a well-defined yet flexible schema for interservice communication.
You want to reduce the number of service calls needed to retrieve business data from a service.

86

45
Q

When to use gRPC?

A

You require low-latency and high-throughput interservice communication.
You want type-safe and robust data exchange between microservices.
The client or the server application needs to build a streaming business operation.

86

46
Q

When to use WebSocket?

A

You have to implement full-duplex efficient messaging between services using your own data formats.

86