Chapter 3, Connectivity and Composition Patterns Flashcards

1
Q

What are native connectivity patterns?

A

Native connectivity patterns allow you to build connectivity among microservices as well as with other systems in your cloud native application. As discussed in Chapter 1, a cloud native application consists of microservices and may also connect with existing proprietary or legacy systems, external services such as software-as-a-service (SaaS) applications, databases, messaging infrastructure such as message brokers, and more.
Page: 95

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

What should be considered when connecting more microservices and systems in a cloud native application?

A

The more microservices and systems we have to connect, the greater the complexity of the entire cloud native application. Before applying connectivity patterns, ensure the appropriate service granularities are used. Too many interactions among microservices indicate a too fine-grained service design scope, necessitating a revisit of the microservice design phase to redefine the service scope directly mapped to business capabilities. The foundational communication patterns should be determined by the business use case. Interactive business capabilities like searching for items in an online store need a synchronous Request-Response pattern, while placing orders requires an asynchronous Single-Receiver pattern. We should identify or define service interaction styles and underlying protocols during the microservice design phase. Ensure infrastructure is not leaked into the application’s connectivity logic to maintain portability. Service connectivity capabilities not mandatory for application behavior should be implemented at other layers, like sidecars.
Page: 100

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

What is a Kubernetes service?

A

A Kubernetes service groups a set of pod endpoints into a single resource. You can configure how you access that service in various ways, such as load balancing or cluster IP.
Page: 105

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

What does a Kubernetes service provide for grouped pods?

A

Kubernetes service provides seamless load balancing among the grouped pods. Using the service type LoadBalancer, Kubernetes automatically creates a cloud network load balancer of the underlying cloud platform (AWS, Azure, GCP, etc.), which provides an externally accessible IP address that sends traffic to the correct port on your cluster nodes.
Page: 106

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

What is the Service Abstraction pattern?

A

With the Service Abstraction pattern, you can expose any other monolithic or proprietary systems consumed by your cloud native application as a service.

Page: 105

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

What are the considerations for using the Service Abstraction pattern?

A

Service Abstraction is essential for cloud native applications to achieve scalability, redundancy, and encapsulation of microservices and other systems. While possible to implement without an underlying platform, using a platform like Kubernetes that supports service abstractions as a first-class construct is recommended.
Page: 106

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

What is a service registry and what information does it contain?

A

A service registry is a repository containing service information and metadata, such as service URLs, service interface definitions, service-level agreements, and other useful information for service consumers. Implemented as a service offering a registry repository API and discovery API, service owners/developers register and maintain the service information, while consumers use the registry to learn how to consume the service.

Page: 107

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

What are the two ways to implement the Service Registry and Discovery pattern?

A

The Service Registry and Discovery pattern can be implemented in two ways: client-side service discovery, where the client is responsible for service discovery, and server-side discovery, where an intermediate component like a load balancer handles service discovery.

Page: 108

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

How does Kubernetes handle service discovery?

A

Kubernetes uses DNS names to discover pods, resolving and mapping service names to actual endpoints. Kubernetes uses etcd as the distributed key-value store for service registry, but it may require a dedicated service registry like Consul for complex service registry and discovery requirements.
Page: 110

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

What should be considered when using the Service Registry and Discovery pattern?

A

Service Registry and Discovery is essential for building cloud native applications. However, a full-blown solution is not necessary from day one, as platforms like Kubernetes and cloud services (AWS, Azure, GCP) offer primitive capabilities. Invest in a dedicated solution if advanced capabilities like managing service dependencies, health checks, and leader election are required.
Page: 111

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

What related patterns are used with the Service Registry and Discovery pattern?

A

Service Registry and Discovery is foundational for most connectivity patterns. In API management, dedicated API registries known as API developer portals are used to store and expose business capabilities as APIs.
Page: 111

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

What is the purpose of a time-out in service calls?

A

A time-out prevents a caller service from waiting indefinitely for a response from a target service, enhancing application responsiveness. Realistic time-out values should be set based on network latency and target service processing time.

Page: 113

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

What is retry logic in resilient connectivity?

A

Retry logic aims to get the expected response despite network disruption by invoking the same service multiple times. Specify the number of retries and duration between retries, and define logic for handling maximum retry count reached.

Page: 114

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

What are deadlines in resilient connectivity?

A

Deadlines specify a fixed point in time for completing a service invocation. They are useful for chains of services, where each service checks the deadline and invokes deadline-exceeded logic if expired.

Page: 115

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

What is a circuit breaker in resilient connectivity?

A

A circuit breaker prevents further service invocations if previous invocations failed and the circuit state reaches a threshold. It switches between closed, open, and half-open states to manage service invocation failures and recovery.

Page: 116

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

What is the fail-fast principle?

A

Fail-fast detects failures related to service connectivity as quickly as possible, often by validating requests before sending them to the target service.

Page: 117

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

What are the considerations for resilient connectivity?

A

Resilient connectivity is essential for cloud native applications and can be implemented as part of the service’s business logic, a separate runtime (sidecar), or via underlying cloud services. Resilient connectivity styles can be combined with various communication patterns.
Page: 119

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

What patterns are often used with the Resilient Connectivity pattern?

A

The Resilient Connectivity pattern is often used with the Sidecar and Service Mesh patterns.
Page: 119

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

How does the Sidecar pattern work for service connectivity?

A

The Sidecar pattern offloads interservice communication logic to a separate runtime colocated with the main microservice. This is often implemented as a colocated container with the main container in Kubernetes pods, allowing clear separation of concerns and easier management and scaling.

Page: 120

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

How is the Sidecar pattern used in practice?

A

The Sidecar pattern is often realized with platforms like Kubernetes, encapsulating a sidecar-based microservices application as a multicontainer pod. This allows clear separation of business logic and enhancement logic while managing and scaling the application as a single unit.

Page: 121

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

What is a sidecar proxy?

A

A sidecar proxy mediates inbound and outbound communication to the main microservices it is attached to, handling additional network communication features like security or service discovery.

Page: 122

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

What is a sidecar bridge?

A

A sidecar bridge allows communication between two different protocols. For example, a main container communicating with HTTP can connect with messaging systems like Kafka through a sidecar bridge.

Page: 123

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

What pattern is closely related to the Sidecar pattern?

A

The Sidecar pattern is closely related to and extended by the Service Mesh pattern.

Page: 126

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

What challenges does the Service Mesh pattern address?

A

The Service Mesh pattern addresses challenges in building connectivity between microservices and systems, offloading interservice communication logic to a different layer to keep service code independent. This pattern is used instead of the centralized ESB architecture, reducing the complexity of business logic and development time.

Page: 126

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

How does the Service Mesh pattern work?

A

Service Mesh implementations define a configuration language or API to control capabilities and manage the data plane via the control plane. Reliability, security, observability, service discovery, and policy enforcement are applied at the data-plane level and controlled through the control plane.

Page: 129

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

What is the relationship between the Service Mesh pattern and other patterns?

A

The Service Mesh pattern is closely related to the Service Connectivity and Sidecar patterns.

Page: 132

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

What is the Sidecarless Service Mesh pattern?

A

The Sidecarless Service Mesh pattern eliminates the need for a sidecar by embedding sidecar proxy logic into the microservice runtime, directly managing and controlling network communication via the control plane.
Page: 132

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

How does the Sidecarless Service Mesh pattern work?

A

The Sidecarless Service Mesh pattern uses a control plane to manage and configure communication between microservices, embedding mesh traffic logic into the microservice runtime. This requires each implementation technology to support the control plane API and network communication logic at each layer.

Page: 133

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

What are the considerations for using the Sidecarless Service Mesh pattern?

A

Sidecarless Service Mesh is an emerging pattern that overcomes the limitations of sidecar-based service mesh architecture. It requires client libraries to support service mesh control plane APIs and network communication logic.

Page: 136

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

What related patterns are associated with the Sidecarless Service Mesh pattern?

A

Sidecarless Service Mesh is an alternative to the Service Mesh pattern with a sidecar proxy. Resilient communication patterns are often implemented at the control plane–compliant client libraries used to build microservices.
Page: 136

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

What is the relationship between Service Orchestration and Service Choreography?

A

Service Orchestration is used alongside Service Choreography in a hybrid way, often requiring both synchronous and asynchronous service interactions.
Page: 145

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

What patterns are used in conjunction with Service Orchestration?

A

Service Choreography is often used with Service Orchestration in a hybrid manner, using asynchronous communication patterns like Single-Receiver and Multiple-Receiver.
Page: 150

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

What is the main protocol used in implementing distributed transactions?

A

Distributed transactions use the two-phase commit (2PC) protocol to orchestrate transaction steps through a transaction manager.
Page: 151

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

What is the two-phase commit (2PC) protocol?

A

The two-phase commit (2PC) protocol coordinates distributed transactions across multiple services. Phase 1 is the preparation phase, where the transaction manager asks all participating services to prepare for the transaction. Phase 2 is the commit phase, where the transaction manager instructs the services to commit or roll back the transaction based on the preparation phase outcomes.
Page: 151

35
Q

When should distributed transactions be used?

A

Distributed transactions should be used cautiously due to complexity, which may hinder system scalability. Alternative data consistency patterns like Event Sourcing or the Saga pattern should be considered.
Page: 151

36
Q

What is the Saga pattern?

A

The Saga pattern manages distributed transactions across multiple services by defining a series of compensating transactions, ensuring data consistency without locking resources across services.
Page: 156

37
Q

What is a key consideration when applying the Saga pattern?

A

The Saga pattern should be used only when absolutely necessary, as managing distributed transactions across multiple services is complex and may hinder system scalability.
Page: 156

38
Q

In what context is the Saga pattern most commonly applied?

A

The Saga pattern is often used on top of Service Orchestration, using data-related patterns for local transactions within each service.
Page: 157

39
Q

Describe The Service Connectivity pattern

A

The Service Connectivity pattern is a high-level, composite pattern that can be used in building cloud native applications. This pattern explains how a cloud native application is formed by connecting microservices and existing systems, and how these services interface with the consumers of the application.

96

40
Q

How does The Service Connectivity pattern work?

A

The Service Connectivity pattern provides a generic way to connect different components such as microservices, external systems, and APIs exposed to consumers. This pattern uses one or more foundational communication patterns such as synchronous or asynchronous communication to establish the connectivity in your cloud native applications. It is applied to the backend implementation of any of the business capabilities of your cloud native application.
So, the key idea of the Service Connectivity pattern is that it should be used as a high-level pattern that connects services and systems to realize the end-to-end business capabilities of a cloud native application.

96

41
Q

Describe The Service Abstraction Pattern

A

When a microservice in a cloud native application needs to interact with another microservice or an external system, it is preferable to use an abstraction that hides the details of the underlying implementation, location, and deployment structure. That is the key idea behind the Service Abstraction pattern. This pattern uses a service to abstract one or more underlying services.

101

42
Q

How does The Service Abstraction Pattern work?

A

A given microservice or any other external system in a cloud native application can be represented as a service, so that it hides all the implementation details. For example, a given service may have multiple runtime instances running in different locations, with different Domain Name System (DNS) names and Internet Protocol (IP) addresses, and so on. If we don’t use an abstraction to represent that microservice, all the clients or other services that consume it need to know the implementation details of the target service or system. Therefore, we can introduce a service abstraction in front of the microservices or systems in a cloud native application (Figure 3-3).

101

43
Q

What are some of the key benefits of using The Service Abstraction Pattern?

A
  • It allows you to use a stable or fixed location (IP) to represent your microservice or system within the cloud native application.
  • It can provide a built-in service-discovery capability, so that the consumer applications refer to the service by using a generic naming scheme that hides the implementation details (for example, http://hostname:port/checkout). This is the key idea behind the Service Registry and Discovery pattern, which allows us to represent all the microservices and systems in our cloud native application at a central location so other consumers can discover existing services or register new services.
  • It can seamlessly provide load balancing and failover.
  • Dynamic scaling of the microservice or system is possible when using a service abstraction, as the underlying instances can come and go as needed.

103

44
Q

What are some considerations to take into account for The Service Abstraction Pattern?

A

Service Abstraction is more or less a mandatory pattern that you need to use when building cloud native applications. The power of the service abstraction is critical to achieve the scalability, redundancy, and encapsulation (hiding the implementation details) of your microservices and other systems. While implementation of the Service Abstraction pattern without using an underlying platform is possible, we recommend using a platform such as Kubernetes that already supports service abstractions as a first-class construct.

106

45
Q

Describe the Service Registry and Discovery Pattern

A

When you build cloud native applications, you need a place to keep the information about the services that you create. This enables consumers to find out all the details of the services. The Service Registry and Discovery pattern can be used for this.

106

46
Q

Describe the Resilient Connectivity Pattern

A

When you are building connectivity among microservices as well as the other systems in your cloud native application, you need to use a network. In distributed computing, the network is always considered to be unreliable. Therefore, we need to make sure that we connect microservices and systems by using resilient connectivity techniques.

111

47
Q

how does the Resilient Connectivity Pattern work?

A

The Resilient Connectivity pattern allows you to design a resilient interaction between the microservice and the other services or systems it invokes, so that if a failure occurs, the system will be able to handle it or recover from it. For example, suppose you have two microservices in your cloud native application: Microservices A and B. Microservice A invokes Microservice B via network communication, and we need to make sure that communication happens resiliently.
The logic that invokes Microservice B should be able to handle the failures that could occur, recover from them if possible, or gracefully take actions to avoid the failure in the future. The key idea here is that Microservice A contains resilient communication logic that is executed as part of the service runtime.
Depending on the nature of the failure that could occur during interservice communication, we may implement the resilient communication logic in different ways, but the high-level architecture implementing resilient communication can be generalized as shown in Figure 3-8.

112

48
Q

What are some of the communication requirements that the Resilient Connectivity Pattern is implemented to handle?

A
  • Time-out
  • Retry
  • Deadlines
  • Circuit Breaker
  • Fail-fast

113

49
Q

Describe the Sidecar Pattern

A

The Sidecar pattern is a generic pattern in which you run a colocated container (application or microservice) along with your main microservice. Sidecar containers extend and enhance capabilities of the main container. In the context of service connectivity, the Sidecar pattern is often used to implement the interservice and intersystem connectivity logic outside your main microservice.

119

50
Q

What are some key considerations to be aware of when using this pattern?

A
  • Using a sidecar along with a microservice multiplies the number of instances you need to manage and run. If you have four microservice instances, then with a sidecar you need to run eight instances.
  • Management of sidecar containers needs to be done via a dedicated control plane component. While it is possible to invoke the configuration API via standard protocols such as HTTP or gRPC, it is more efficient and easier to manage sidecars via a dedicated control plane component.
  • Sidecar configuration can rapidly grow to complex logic. The more services and systems that you connect with, the more complex the sidecar configuration that you need to manage.
  • Never implement any business-logic-related capability inside the sidecar. That would violate the key purpose of the Sidecar pattern; the leaking of business logic to multiple layers also may have adverse consequences such as management and ownership nightmares.

125

51
Q

Describe the Service Mesh Pattern

A

The Service Mesh pattern is essentially an extension of the Sidecar pattern, to be used as the communication infrastructure of a cloud native application.

126

52
Q

How does Service Mesh Pattern work?

A

The Service Mesh pattern allows you to have an interservice communication infrastructure between your microservices and other systems. With a service mesh, a given microservice won’t directly communicate with the other microservices. Rather, all service-to-service communications take place through a sidecar proxy. As illustrated in Figure 3-18, the Service Mesh pattern introduces the following components to provide a simple, scalable, and configurable communication infrastructure:

-Service Mesh sidecar proxy
This is known as the data plane, in which all the interservice communication logic is applied to the messages exchanged between services and systems.

  • Control plane
    Sidecar proxies are controlled through the control plane. This centralized component provides a rich and simple API to control sidecar proxies of the data plane.
  • Service Mesh configuration language
    This is the configuration API that allows you to configure the data plane to control the interservice communication logic.
  • Built-in support
    This support provides reliability, security, observability, service discovery, policy enforcement, and more.

127

53
Q

What are some considerations to keep in mind for the Service Mesh Pattern?

A

Although the Service Mesh pattern is a popular concept these days, adopting it in the real world to build cloud native applications should be done with caution. Here’s why:

  • Managing a service mesh deployment can be overwhelmingly complex. The complexity comes from the sidecar architecture (in which we need to run one extra container for each service instance) as well as from the architecture of the service mesh implementation (we need to manage multiple service mesh components that interact with each other).
  • A service mesh is often built on top of containers and container orchestration platforms such as Kubernetes. This may double the complexity that it brings in.
  • Running and managing a fleet of sidecar proxies carries a major performance overhead.
  • Service Mesh doesn’t offer first-class support for asynchronous event-driven communication yet.

131

54
Q

When to use Service Connectivity pattern?

A

This is a generic pattern that you can use to build connectivity in almost all the cloud native applications.

138

55
Q

When to use Service Abstraction pattern?

A

Usually, you need to explicitly use it if you are using Kubernetes or a cloud service.
Useful when you connect cloud native applications with existing monolithic systems.

138

56
Q

When not to use Service Abstraction pattern?

A

Not required to specifically use this pattern when you are fully dependent on a cloud service or a serverless platform.

138

57
Q

When to use Service Registry and Discovery pattern?

A

A fully fledged service registry and discovery solution is required if you have several dozen services consumed by a wide range of clients across the organization and beyond.
For most use cases, the foundational service registry and discovery offered from platforms such as Kubernetes should be sufficient.
If you use a cloud service such as AWS, Azure, or GCP, most of the capabilities are available out of the box.

138

58
Q

When not to use Service Registry and Discovery pattern?

A

If the number of services that you need to connect is small, having a full-blown service registry and discovery service doesn’t make sense.
You will still need a primitive service discovery mechanism (for example, DNS) to encapsulate service location and deployment details.

138

59
Q

When to use Service Resilience pattern?

A

Often required when building a reliable cloud native application that connects with multiple services and systems.
Essential for connecting legacy systems with cloud native applications.
Explicitly implement resilience if the underlying cloud service or deployment (for example, service mesh) doesn’t support resilient connectivity.

138

60
Q

When not to use Service Resilience pattern?

A

Not required to explicitly use if you are building the application on top of a service mesh, cloud service, or using a serverless platform (they offer out-of-the-box support for resilient connectivity for the most part).

138

61
Q

When to use Sidecar pattern?

A

Useful when you have to decouple the business logic from the connectivity logic.
If the connectivity logic is too complex, offloading it to a separate runtime makes sense.
You use polyglot technologies that require the same connectivity features.

138

62
Q

When not to use Sidecar pattern?

A

Not suitable if your DevOps don’t have the capacity to handle the complexity of sidecar architecture.
If you don’t use container orchestration, it’s overwhelmingly complex to support sidecar architecture.

138

63
Q

When to use Service Mesh pattern?

A

You have to connect numerous microservices to achieve resilience, traffic routing, secured communication, service discovery, and observability.
138

64
Q

When to use Sidecarless Service Mesh pattern?

A

Useful if the sidecar architecture hinders performance.
The underlying implementation technology supports sidecarless interaction with control planes.

138

65
Q

When not to use Sidecarless Service Mesh pattern?

A

Still at very early stages. So, it is better to avoid it unless the pattern is offered from the technology stack or cloud provider (for example, GCP Traffic Director).

138

66
Q

Describe Service Composition Patterns

A

Service composition is all about how you implement a business use case by plumbing, or integrating, multiple services and systems. It’s important to keep in mind that the services that we build use existing services, and should have a clear business scope and be driven by clear business requirements. We cannot simply create composite services by randomly connecting them. For instance, if you want to support a certain business capability (such as order management), you should come up with the API of the composite service and the downstream services and systems that you want to integrate with.

141

67
Q

Describe the Service Orchestration Pattern

A

In the context of cloud native applications, when we have to build a business capability by invoking multiple services and systems, the composition logic is implemented in a single microservice. This pattern, for the most part, uses synchronous communication and operates in a stateless way.

141

68
Q

How does the Service Orchestration Pattern work?

A

Service Orchestration implements the business logic of a microservice by invoking and integrating one or more microservices and systems. Suppose you are building a new business capability implemented as Microservice Z (Figure 3-22). It requires the integration of several existing microservices such as Microservices A, B, and C. You can build the business logic of Microservice Z so that it invokes Microservices A, B, and C with the required messages and finally sends the response back to the consumer of Microservice Z. The downstream services may use disparate message formats and communication protocols. Therefore, Microservice Z needs to handle all that complexity. The entire composition logic is self-contained within Microservice Z’s scope.
The downstream services can use either synchronous or asynchronous communication. These downstream services may call several other downstream services too. This style of communication is known as service chaining. From the perspective of composite services such as Microservice Z, the existence of multiple chained downstream services is irrelevant.

141

69
Q

How is Service Orchestration Pattern used in practice?

A

Service Orchestration is commonly used in most cloud native applications, as microservices need to integrate with one or more other microservices or systems when implementing a given business capability.

143

70
Q

What are some considerations we need to be aware when using the Service Orchestration Pattern?

A
  • Use this pattern if it can be directly mapped to a business capability that aggregates the capabilities of several other downstream capabilities. Otherwise, you will be creating a monolithic service with multiple business capabilities.
  • Service Orchestration is straightforward to implement in scenarios that are stateless, so we don’t need to worry about preserving the state of the orchestration.
  • It is better to limit the number of service calls in a composition. For instance, if you have to orchestrate calls among more than four or five services, that’s a sign of business scope issues with the service, or perhaps the downstream services may be too granular.
  • Service Orchestration centralizes the composition logic to a single service, and that service is tightly coupled to all the downstream services that it connects with.

Avoid using a conventional monolithic technology such as an ESB or a workflow engine to implement the orchestration logic, as they are not designed for building cloud native applications.

The composite services that we develop by using Service Orchestration are exposed to the consumers via an API management layer

144

71
Q

Describe the Service Choreography Pattern

A

When building service compositions, we don’t always want to centralize the composition logic to a single service. In some cases, we need to build it across multiple services. The Service Choreography pattern creates service compositions by using asynchronous communication between microservices and other systems.

145

72
Q

How does the Service Choreography Pattern work?

A

At the heart of the Service Choreography pattern, we build a business use case that requires interaction among multiple microservices and other systems by creating asynchronous event-driven communication links with the use of a message broker (or event hub). The interaction logic is dispersed across multiple microservices, and no direct coupling occurs between microservices. Unlike in the Service Orchestration pattern, microservices do not actively invoke other microservices, but operate more or less in a reactive mode based on the events and messages coming into the service. Hence the microservices that we use in Service Choreography are also known as reactive microservices.

The composition logic is formed by publishing messages to queues or topics and the consumer microservices subscribing to them. By using asynchronous messaging patterns such as Single-Receiver (queue-based) or Multiple-Receiver (pub-sub with topics), we can create distributed asynchronous composition logic across multiple microservices.

It’s important to note that in the Service Choreography pattern, we use the message broker as a primitive messaging infrastructure. We don’t put any business logic (such as routing based on a certain criteria) inside the broker. All the logic should reside inside either producer or consumer microservices.

146

73
Q

What are some of the key considerations to be aware of when adopting the Service Choreography pattern?

A
  • Service composition logic is dispersed across multiple microservices. Unlike in Service Orchestration, you can’t understand the business logic of a choreography scenario by just looking at a single service.
  • Services are loosely coupled. Adding or removing services is much easier with the Service Choreography pattern compared to Service Orchestration.
  • Because of the event-driven and asynchronous nature of the Service Choreography pattern, you can implement it by using a serverless platform. For instance, you can model all the event-driven microservices as serverless functions.

149

74
Q

Describe the Saga Pattern

A

When we create service compositions by using multiple microservices, we may have to execute those service interactions in a transactional way (for example, if one service interaction fails, the rest of the service interactions should be rolled back). As the transaction boundary of such a scenario spans multiple microservices and other systems, this is known as a distributed transaction.

The Saga pattern provides a way to build distributed transactions that span multiple microservices. It does this by using corresponding compensation operations to undo every service interaction that is part of a single distributed transaction.

150

75
Q

How does the Saga Pattern work?

A

The Saga pattern aims to build distributed transactions across multiple microservices and other systems by breaking a given transaction into a sequence of subtransactions and corresponding compensating transactions. All transactions in a Saga either complete successfully, or, in the event of a failure, compensating transactions are executed to roll back all subtransactions.

151

76
Q

Distributed transactions have inherent limitations, which hinder their usage with 2PC for most microservice use cases that require transactions. List some of these limitations.

A

Distributed transactions have inherent limitations, which hinder their usage with 2PC for most microservice use cases that require transactions. List some of these limitations.

  • The transaction manager is the single point of failure. Pending transactions will never complete if the transaction manager is unavailable.
  • If a given participant fails to respond, the entire transaction will be blocked.
  • The 2PC protocol assumes that if a given participant has agreed to commit a transaction by responding Yes to the transaction manager, then it can definitely commit the transaction too. This is not the case with most of the practical scenarios. The participant may fail to commit a transaction although it has responded Yes.

151

77
Q

List some of the considerations to be aware of when using the Saga pattern

A
  • The implementation of the Saga pattern requires a Saga framework or a workflow engine solution that supports stateful execution (that is, the Saga Execution Coordinator) of the business transaction between services. Implementing everything from scratch is generally not recommended because of the complexity involved.
  • Running an observability solution alongside a Saga implementation is essential, as we have to debug and troubleshoot complex business transactions across distributed services.
  • A Saga implementation framework should be backed by a scalable distributed log, as a single transaction may emit a multitude of events to the Saga log.

156

78
Q

When to use Service Orchestration pattern?

A

The business use case requires one service to handle all the interactions with other services and systems.
Usually suitable for interactive services.

158

79
Q

When not to use Service Orchestration pattern?

A

Not suitable if the coupling between services is a concern.
Not suitable when the majority of your use case is based on asynchronous messaging for events.

158

80
Q

When to use Service Choreography pattern?

A

You require service composition across event-driven microservices.
You want to build fully decoupled microservices in a cloud native application.

158

81
Q

When not to use Service Choreography pattern?

A

Not well suited for interactive services such as APIs that are exposed to consumers.

158

82
Q

When to use Saga pattern?

A

Distributed transactions across multiple microservices are essential.

158

83
Q

When not to use Saga pattern?

A

Not useful when the services cannot offer compensating operations that can execute transactionally.
You shouldn’t adopt it unless you have a framework or solution that can build the Saga execution for you. (Implementing Saga from scratch is overwhelmingly complex.)

158