Wednesday , October 30 2024

Reactive Architecture: Distributed Messaging Patterns cognitive class Answers:-

Course Name :- Reactive Architecture: Distributed Messaging Patterns

Chapter Name :- Message Driven Architecture

Evolution of communication

Question 1:-Which of the following are real world analogues for Synchronous Communication?

  • Phone Calls
  • Text Message
  • Email
  • Video Chat
  • Handwritten Letters
  • In Person Conversations

Question 2 : True or False: Synchronous communication can be substituted for Asynchronous communication without issues, but the reverse is not true.

  • True
  • False

Message driven architecture

Question 1 : A principle of a Reactive System is that it is:

  • Scalable
  • Event Driven
  • Robust
  • Message Driven

Question 2 : True or False: An Asynchronous, Non-Blocking message requires a response.

  • True
  • False

Question 3 : A key benefit to Asynchronous, Non-Blocking messages is:

  • Guaranteed Delivery
  • Rapid Response Time
  • Improved Consistency
  • Efficient Resource Usage

Question 4 : True or False: Asynchronous, Non-Blocking messages reduce contention in a system, which in turn improves scalability.

  • True
  • False

Question 5 : When an asynchronous message needs to be delivered to an offline service we should:

  • Try sending the message to an alternate destination.
  • Drop the message.
  • Return a failure to the user.
  • Put the message into a queue and deliver it when the service is back online.

Question 6 : The backbone of a Reactive System should be built on:

  • Synchronous Non-Blocking Messages
  • Synchronous Blocking Messages
  • Asynchronous Blocking Messages
  • Asynchronous Non-Blocking Messages

Question 7 : True or False: There is no place for Synchronous Messages in a Reactive System.

  • True
  • False

Question 8 : The decision of where to use Synchronous Messages should be driven by:

  • The underlying development framework
  • The choice of message protocol
  • Ease of implementation
  • Domain Requirements

Question 9 : Using transactions that cross microservice boundaries should be avoided because:

  • Some services may be unavailable.
  • Multiple databases may be involved.
  • Long running transactions increase contention.
  • All of the above
  • None of the above

Case Study:-

Question 1 : In the Reactive BBQ, an order is sent to the kitchen to be prepared using the “PrepareOrder” command. Once the order has been completely prepared, the front of house staff can be notified that the order is ready by issuing an “OrderPrepared” event.

This is best described as using:

  • Synchronous Messages
  • Asynchronous Messages

Question 2 : When a customer is paying for their order at the till, a “CollectPayment” command is issued through the Payment UI. The UI will then wait while the command is processed by the Payment service which performs the necessary validation. Once the payment has been collected and verified, a response is sent back to the UI indicating whether the payment was successful or not, and the UI can then proceed with the next step of the process.

This is best described as using:

  • Synchronous Messages
  • Asynchronous Messages

Question 3 : In the new Reactive BBQ system, we want to add a Loyalty program. The addition of the Loyalty program means that when a customer pays for their order, we also need to issue Loyalty points. Issuing Loyalty points will be done with a separate backend service called the Loyalty Service.

If the Loyalty Service was unavailable for some reason we would want to:

  • Fail the payment process, but keep the payment.
  • Delay completing the payment process, and continue to retry the Loyalty Service until it succeeds.
  • Fail the payment process, and rollback any payments.
  • Complete the payment process successfully, and continue to retry the Loyalty Service until it succeeds.

Question 4 : An order in the Reactive BBQ Order Service is considered “Closed” once we have decided that no more items can be added to that order. For a typical dine in order this occurs once the customer has paid for the order. After that, if they want to order more, a new order will have to be created. Similarly, for an online order, the order is considered closed once the customer has completed the payment.

This means that with the addition of the Loyalty Service there is a multistep process to complete when a customer pays for an order. We need to (in no particular order):

  • Collect the Payment
  • Close the Order
  • Award Loyalty Points

Question 5 : Which of these steps can be completed asynchronously (i.e. after the customer has left the restaurant or closed the online order page).

  • Collect the Payment
  • Close the Order
  • Award Loyalty Points

Question 6 : In the Reactive BBQ, it is a fairly common occurrence for a table to be re-assigned to a different server. This can happen when a server goes on a break or when a server leaves at the end of their shift. When this happens, a server will issue a “AssignServerToOrder” command which will be processed by the system to make the appropriate change.

In the old system, this was done using a synchronous request-response pattern. In the new system we would like to make it more Reactive.

This operation could be made more Reactive by:

  • Leveraging a distributed transaction to ensure the update happens in a strongly consistent fashion.
  • Issuing the command to multiple instances of the orders microservice, and then taking the first response to come back.
  • Developing an Remote Procedure Call (RPC) for the command in order to hide the presence of the network.
  • Synchronously acknowledging that the command was received, but processing it asynchronously.

Chapter Name :- Sagas:-

Question 1: A Saga can be described as:

  • A way to allow cross service transactions to “roll forward” in the event of failure.
  • A distributed transaction.
  • A way to represent a long running transaction in a distributed system.
  • A long story of heroic achievement.

Question 2 : True or False: Sagas can be run in sequence or in parallel.

  • True
  • False

Question 2 : Sagas are often modelled as:

  • Free Monad Structures
  • A Finite Sequences of Events
  • Functional Sequence Monoids
  • Finite State Machines

Question 3 : Compensating actions are run for:

  • All failed steps.
  • All incomplete steps.
  • All steps
  • All completed steps.

Question 4 : If a compensating action fails we:

  • Log an error and notify the Ops team.
  • Disregard that action and move on to the next.
  • Apply a different compensating action instead.
  • Retry the compensating action until it succeeds.

Question 5 : Compensating actions must be:

  • Derivative
  • Distributive
  • Associative
  • Idempotent

Question 6 : A timeout on a request means:

  • The request is queued.
  • The request succeeded.
  • The request failed.
  • All of the above.
  • None of the above.

Question 7 : Because of timeouts, compensating actions must also be:

  • Integral
  • Deductive
  • Communicative
  • Commutative

Question 8 : True or False: In the event of a timeout, we should run the corresponding compensating action.

  • True
  • False

Question 9 : Compensating actions are different from Rollbacks because:

  • A rollback assumes the original action is complete
  • A rollback happens after the original action
  • A rollback removes evidence of the original action
  • All of the above
  • None of the above

Question 10 : True or False: A big benefit to Sagas is the way they let us move forward when a failure occurs.

  • True
  • False

Question 11: The feature of Akka that supports the creation of Sagas is:

  • Akka Distributed Data
  • Akka Persistence Query
  • Akka Cluster Sharding
  • Akka Persistent FSM (Finite State Machine)

Case Study :- Sagas

Question 1 : In a previous exercise we described the scenario where a customer pays for the order and we must complete three separate steps. These steps included:

  • CollectPayment
  • CloseOrder
  • AwardLoyaltyPoints

The development team is experimenting with the idea of using a Saga to help encapsulate these steps. The following questions will address the implementation of that Saga.

Question 2 : One of the first things we will need to do, is determine appropriate compensating actions for each of the steps in the saga.

Think about the criteria that make up a good compensating action.

  • What happens if the compensating action gets handled twice?
  • Do we need to keep a history of the previous actions?
  • Is the compensating action “intent revealing”?

Question 2 : Which of the following would be the best compensating action for “CollectPayment”?

  • RollbackPayment – The log is rolled back to before the payment completed. Any items from the payment onward are removed.
  • DeletePayment – The existing payment is deleted. The original payment no longer appears in the log.
  • ApplyCredit – The customers account is credited for the amount of the payment. The original payment and credit appear in the log.
  • RefundPayment – The existing payment is refunded. The original payment and refund appear in the log.

Question 3 : Which of the following would be the best compensating action for “CloseOrder”?

  • OpenOrder – A new order is opened containing the details of the old order. Both old and new order appear in the log.
  • ReopenOrder – The existing order is re-opened. The close and re-open both appear in the log.
  • RollbackOrderClosed – The order is rolled back to a previous state. Any evidence that the order was closed is removed.
  • SetOrderAsOpen – A status on the order is changed from “closed” to “open”. The previous state is not maintained.

Question 4  :- Which of the following would be the best compensating action for “AwardLoyaltyPoints”?

  • DeductLoyaltyPoints – Loyalty points are deducted in the amount of award. The award and deduction both appear in the log.
  • CancelLoyaltyPointsAwarded – The award is cancelled. The original award, and the cancellation both appear in the log.
  • RollbackLoyaltyPoints – The loyalty points are rolled back to a specific point. Any changes after that point are removed from the log.
  • SetLoyaltyPoints – The loyalty points are set to a specific value. The original award, and the new value both appear in the log.

Question 5 :- As part of building this saga, we want to ensure that once we have the payment, we rarely, or never have to run the compensating action for “Complete Payment”.

In order to do this, “Complete Payment” should be:

  • Completed first
  • Completed second
  • Completed last
  • Completed in parallel with other actions

Question 6 : Assuming we have set up our Saga to perform the steps in the following order:

Close Order => Award Loyalty => Complete Payment

If we receive a timeout on the Award Loyalty step, which actions do we need to compensate for?

  • Close Order
  • Award Loyalty
  • Complete Payment

Note: Make sure you select all of the correct options—there may be more than one!

Question7 : If instead of a timeout, we receive a legitimate failure for the Award Loyalty (i.e. we can confirm that it failed), then which actions do we need to compensate for?

  • Close Order
  • Award Loyalty
  • Complete Payment

Note: Make sure you select all of the correct options—there may be more than one!

Question 8 : The saga solution we have provided is interesting, but it has some drawbacks.

Which of the following could be considered drawbacks of using the Saga solution in this case:-

  • A failure to close the order could result in us not collecting the payment.
  • A failure to award loyalty points could result in us not collecting the payment.
  • A failure collect payment means that we don’t award the loyalty points.
  • A failure collect payment means that we don’t close the order.

Chapter name : Messaging patterns

Two generals

Question 1 :The Two Generals Problem demonstrates:

  • That two phase commit protocols can not ensure consistency in a distributed system.
  • The impact of synchronous messages on a distributed system of at least two nodes.
  • That distributed transactions are brittle and prone to failure.
  • That it is impossible to reach a consensus over an unreliable communication channel.

Question 2 : The Two Generals problem is relevant to software where the unreliable communication channel is usually represented by:

  • The Disk
  • An Enterprise Service Bus
  • The Database
  • The Network

Question 3 : The messengers in the Two Generals Problem map to what concept in a Reactive System?

  • The Database
  • Microservices
  • Shared State
  • Messages (both synchronous and asynchronous)

Delivery guarantee:-

Question 1 : In order to guarantee message delivery we require:

  • A reliable communication channel.
  • An embedded tracking cookie.
  • An acknowledgement back from the receiver.
  • A chain of reliable postal workers.

Question 2 : True or False: One consequence of The Two Generals Problem is that due to potential loss of messengers, Exactly Once delivery of messages is impossible.

  • True
  • False

Question 3 : In a distributed system, we can have which of the following:

  • At Most Once Delivery
  • At Least Once Delivery
  • At Least Once Delivery with Deduplication
  • Exactly Once Delivery

Question 4 : When using At Most Once Delivery, if a message fails to be delivered we will:

  • Retry the message until it succeeds.
  • Retry the message at most once.
  • Retry the message more than once.
  • Lose the message.

Question 5 : At Most Once Delivery requires:

  • Message storage on the sender and receiver.
  • Message storage on the sender.
  • Message storage on the receiver.
  • No message storage.

Question 6 : When using At Least Once Delivery, if a message fails to be delivered we will:

  • Retry the message more than once.
  • Lose the message.
  • Retry the message at most once.
  • Retry the message until it succeeds.

Question 7 : At Least Once Delivery requires:

  • Message storage on the sender and receiver.
  • No message storage.
  • Message storage on the receiver.
  • Message storage on the sender.

Question 8: Exactly Once Delivery is impossible because:

  • Resending messages in the event of a failure results in duplication.
  • All networks are unreliable.
  • In the event of a timeout, we don’t know if the message was received or not.
  • All of the above
  • None of the above

Question 9 : Effectively Once Delivery relies on:

  • At Most Once Delivery
  • At Least Once Delivery
  • Exactly Once Delivery
  • Idempotence or Deduplication

Question 10 : Effectively Once Delivery requires:

  • Message storage on the receiver.
  • Message storage on the sender.
  • No message storage.
  • Message storage on the sender and receiver.

Question 11: The default delivery guarantee in Akka is:

  • Exactly Once
  • At Least Once
  • Effectively Once
  • At Most Once

Question 12: True or False: Once you start using At Least Once Delivery, you must use it everywhere.

  • True
  • False

Messaging patterns:-

Question1 : We can describe dependencies in a Point 2 Point system by saying:

  • Microservices depend on each other indirectly.
  • Microservices depend on an Enterprise Service Bus which links services indirectly.
  • Microservices depend directly on each other.
  • Microservices can claim their dependencies on their income tax.

Question 2 : Which of the following is true of a Point 2 Point system:

  • Dependencies are clearly defined.
  • Services are directly coupled to their dependencies.
  • Services have no direct knowledge of each other.
  • Dependencies are always managed using a service locator.
  • Complexity is hidden in abstraction layers.

Question 3 : Publish/Subscribe relies on some form of:

  • Enterprise Message Broker
  • Enterprise Service Bus
  • Command Broker
  • Message Bus

Question 4 : In a Publish/Subscribe system, messages are:

  • Sent to the message bus by a publisher
  • Sent to the message bus by a subscriber
  • Delivered to each subscriber by the message bus
  • Delivered to each publisher by the message bus
  • Delivered to only one place

Question 5 : True or False: When using Publish/Subscribe, microservices are not required to know about each other.

  • True
  • False

Question 6 : Which of the following are true about a Publish/Subscribe system?

  • Services are coupled to the message format and message bus, not to each other.
  • Coupling is high.
  • Complex dependencies can be hard to detect.
  • Indirect dependency allows for flexibility in how messages are provided or consumed.
  • Message formats must be rigidly defined and can not change over time.

Question 7: True or False: Distributed systems should be built using only point to point or publish/subscribe. You should never try to use both.

  • True
  • False

Question 8 : True or False: A Message Bus is just another name for an Enterprise Service Bus.

  • True
  • False

Question 9 : The responsibilities of a Message Bus in a Reactive System include:

  • Manage versioning of messages
  • Control deployment of services
  • Manage backpressure between services
  • Route messages to services
  • Provide exactly once delivery semantics

Question 10 : True or False: Akka and Lagom include facilities to support both Point to Point style messaging and Publish/Subscribe. Publish/Subscribe can be done with or without an external message bus.

  • True
  • False

Case Study :-

Question 1: In the Saga solution, which of the following messages are processed asynchronously (i.e. after the customer has left)?

  • CollectPayment
  • CloseOrder
  • AwardLoyaltyPoints
  • None of the Above

Question 2 : In the Message Driven solution, which of the following messages are processed asynchronously (i.e. after the customer has left)?

  • CollectPayment
  • CloseOrder
  • AwardLoyaltyPoints
  • None of the Above

Question 3: In the Saga solution, all of the messages are handled using the same delivery guarantee.

The delivery guarantee for the messages shown in the Saga solution is:

  • At Most Once
  • At Least Once
  • Exactly Once

Question 4: What delivery guarantee is most likely used when we send the “CollectPayment” message to the “Payments” service?

  • At Most Once
  • At Least Once
  • Exactly Once

Question 5 : What delivery guarantee is most likely used when we send the “PaymentCollected” message to the “Orders” service?

  • At Most Once
  • At Least Once
  • Exactly Once

Question 6: What delivery guarantee is most likely used when the “Orders” service sends the “CloseOrder” message back to itself?

  • At Most Once
  • At Least Once
  • Exactly Once

Question 7: Which of the following messages are delivered to the services using Point to Point?

  • CollectPayment
  • AwardLoyaltyPoints
  • CloseOrder
  • PaymentCollected (From the Message Bus to Loyalty and Orders)

Question 8 : Which of the following messages are delivered to the services using Publish/Subscribe?

  • CollectPayment
  • AwardLoyaltyPoints
  • CloseOrder
  • PaymentCollected (From the Message Bus to Loyalty and Orders)

Reactive Architecture: Distributed Messaging Patterns final exam answers:-

Question 1: Scalable Games is using which messaging pattern?

  • Scalable Games is an online gaming company. They have built a new game that they are hoping will have millions of users.
  • A key part of their infrastructure is the ability for users to manage lists of friends. Users can trade items with their friends, send them messages, and interact with those friends in the game. In order for this to work, friends need to know what each other is doing. One of the features they have is a notification service which will send popup notifications based on friend activities. This means that if a friend comes online then users will get a notification. Or if a friend wants to trade an item, they get a notification.
  • In order for this to work, certain types of events are sent to a centralized messaging platform. The notification service can then listen to these events and consume them in order to produce the desired popup.

Question 2 : Available advertising is using _______ messages to consume this data feed.

  • Available Advertising has built a pipeline to consume data from a variety of advertising networks. This data is then syndicated to a number of destinations through their Syndication Service.
  • Each of their advertising networks has a different way of obtaining the data. One network has them send a HTTP request for data. The network will then return a URL which they can use to obtain the requested data. Another HTTP request is sent to that URL which will return a portion of the data, and another URL if there is more to collect. They continue to consume each URL until they have obtained the entire data feed.

Question 3 : Saga Electronics can achieve what they are looking for by using which delivery guarantee?

  • Saga Electronics is an online retailer focusing on Electronics.
  • Their system has a Checkout Service, which is responsible for managing the final steps of the checkout process for a customer. Once the checkout has been completed, the information is sent on to the Fulfillment Service. This service manages the process of getting the product to the customer.
  • It is absolutely critical that the handover from the Checkout Service to the Fulfillment Service is successful. If for example, they attempted to send the order for fulfillment and it somehow got lost, then this would result in a customer who has paid for a product, but never received it. This kind of situation needs to be avoided at all costs.

Question 4 : Consistent Fitness is using what delivery guarantee for the messages to the server?

  • Consistent Fitness has built a microservice that receives data from their wearable fitness trackers. The fitness trackers will connect to the server and then upload whatever data has not currently been synced to the server. Once the data has been uploaded to the server, it can potentially be purged from the fitness tracker.
  • Sometimes the server is unavailable. When the server is unavailable any messages being sent to it fail. The fitness tracker doesn’t bother retrying those messages. Instead it simply gives up. The data is still stored on the fitness tracker and the next time we attempt to sync up with the server it will just upload then (including any new data received since). In that respect, it’s not critical that the server receive every message.

Question5 : Spectrum messages is making use of _______ Messages.

  • Spectrum Messages has a mobile application that provides instant messaging and chat features.
  • One feature of the Spectrum Messages application is that it allows users to see when their messages have been read. The way this works is that the original message is sent by the sender. This message may take some time to arrive on the receiver’s end, depending on whether the receiver is connected, whether there phone is turned on etc. Once the message is received, and opened, a notification is sent back to the original sender to indicate that the message was viewed.

Question 6  : Two Generals Video is using which messaging pattern?

  • Two Generals Video, a video streaming company, has built a platform for providing streaming video.
  • There system is made up of a number of different microservices. The Streaming Service handles the actual streaming of the videos. The Video Inventory service manages the list of videos they have available. They also have a Watch History service that manages the details about which videos have been watched by which users. Finally they have a Menu Service which manages the details about how to display the Menu for each user.
  • In order for the Menu service to operate, it needs a variety of different information. It needs a list of videos to display. To get that it makes a request to the Video Inventory service. At the same time they also need to filter videos based on what the user has already watched. To do that it makes a request to the Watch History service. It can then take that information and aggregate it to display the menu. Finally, once a user has decided what to watch, the Menu Service needs to make a request to the Streaming Service in order to begin streaming the video.

Question 7 : In order to ensure that both steps in the process succeed, or none of them do, CQRS Auto can leverage which pattern?

  • CQRS Auto is a automobile trading company formed in the 1980s by four partners (Christa, Quentin, Rhonda, and Samuel). They have since grown to be one of the largest auto traders in the nation.
  • Recently they partnered with ES Financial. This new partnership allows them to offer financing on vehicles purchased through their website. With this new setup, a user can log into the site, find a car that they like, setup financing, and purchase the vehicle, all at the same time.
  • The financing can take some time to go through. As a result sometimes the car they tried to purchase will be sold by the time the financing is complete. Or they may indicate they want to purchase the car, only to discover that the financing wasn’t approved. In either case if one thing fails they probably don’t want to proceed. They won’t want the

Course Name :- Reactive Architecture: Distributed Messaging Patterns

Chapter Name :- Message Driven Architecture

Evolution of communication

Question 1:-Which of the following are real world analogues for Synchronous Communication?

  • Phone Calls
  • Text Message
  • Email
  • Video Chat
  • Handwritten Letters
  • In Person Conversations

Question 2 : True or False: Synchronous communication can be substituted for Asynchronous communication without issues, but the reverse is not true.

  • True
  • False

Message driven architecture

Question 1 : A principle of a Reactive System is that it is:

  • Scalable
  • Event Driven
  • Robust
  • Message Driven

Question 2 : True or False: An Asynchronous, Non-Blocking message requires a response.

  • True
  • False

Question 3 : A key benefit to Asynchronous, Non-Blocking messages is:

  • Guaranteed Delivery
  • Rapid Response Time
  • Improved Consistency
  • Efficient Resource Usage

Question 4 : True or False: Asynchronous, Non-Blocking messages reduce contention in a system, which in turn improves scalability.

  • True
  • False

Question 5 : When an asynchronous message needs to be delivered to an offline service we should:

  • Try sending the message to an alternate destination.
  • Drop the message.
  • Return a failure to the user.
  • Put the message into a queue and deliver it when the service is back online.

Question 6 : The backbone of a Reactive System should be built on:

  • Synchronous Non-Blocking Messages
  • Synchronous Blocking Messages
  • Asynchronous Blocking Messages
  • Asynchronous Non-Blocking Messages

Question 7 : True or False: There is no place for Synchronous Messages in a Reactive System.

  • True
  • False

Question 8 : The decision of where to use Synchronous Messages should be driven by:

  • The underlying development framework
  • The choice of message protocol
  • Ease of implementation
  • Domain Requirements

Question 9 : Using transactions that cross microservice boundaries should be avoided because:

  • Some services may be unavailable.
  • Multiple databases may be involved.
  • Long running transactions increase contention.
  • All of the above
  • None of the above

Case Study:-

Question 1 : In the Reactive BBQ, an order is sent to the kitchen to be prepared using the “PrepareOrder” command. Once the order has been completely prepared, the front of house staff can be notified that the order is ready by issuing an “OrderPrepared” event.

This is best described as using:

  • Synchronous Messages
  • Asynchronous Messages

Question 2 : When a customer is paying for their order at the till, a “CollectPayment” command is issued through the Payment UI. The UI will then wait while the command is processed by the Payment service which performs the necessary validation. Once the payment has been collected and verified, a response is sent back to the UI indicating whether the payment was successful or not, and the UI can then proceed with the next step of the process.

This is best described as using:

  • Synchronous Messages
  • Asynchronous Messages

Question 3 : In the new Reactive BBQ system, we want to add a Loyalty program. The addition of the Loyalty program means that when a customer pays for their order, we also need to issue Loyalty points. Issuing Loyalty points will be done with a separate backend service called the Loyalty Service.

If the Loyalty Service was unavailable for some reason we would want to:

  • Fail the payment process, but keep the payment.
  • Delay completing the payment process, and continue to retry the Loyalty Service until it succeeds.
  • Fail the payment process, and rollback any payments.
  • Complete the payment process successfully, and continue to retry the Loyalty Service until it succeeds.

Question 4 : An order in the Reactive BBQ Order Service is considered “Closed” once we have decided that no more items can be added to that order. For a typical dine in order this occurs once the customer has paid for the order. After that, if they want to order more, a new order will have to be created. Similarly, for an online order, the order is considered closed once the customer has completed the payment.

This means that with the addition of the Loyalty Service there is a multistep process to complete when a customer pays for an order. We need to (in no particular order):

  • Collect the Payment
  • Close the Order
  • Award Loyalty Points

Question 5 : Which of these steps can be completed asynchronously (i.e. after the customer has left the restaurant or closed the online order page).

  • Collect the Payment
  • Close the Order
  • Award Loyalty Points

Question 6 : In the Reactive BBQ, it is a fairly common occurrence for a table to be re-assigned to a different server. This can happen when a server goes on a break or when a server leaves at the end of their shift. When this happens, a server will issue a “AssignServerToOrder” command which will be processed by the system to make the appropriate change.

In the old system, this was done using a synchronous request-response pattern. In the new system we would like to make it more Reactive.

This operation could be made more Reactive by:

  • Leveraging a distributed transaction to ensure the update happens in a strongly consistent fashion.
  • Issuing the command to multiple instances of the orders microservice, and then taking the first response to come back.
  • Developing an Remote Procedure Call (RPC) for the command in order to hide the presence of the network.
  • Synchronously acknowledging that the command was received, but processing it asynchronously.

Chapter Name :- Sagas:-

Question 1: A Saga can be described as:

  • A way to allow cross service transactions to “roll forward” in the event of failure.
  • A distributed transaction.
  • A way to represent a long running transaction in a distributed system.
  • A long story of heroic achievement.

Question 2 : True or False: Sagas can be run in sequence or in parallel.

  • True
  • False

Question 2 : Sagas are often modelled as:

  • Free Monad Structures
  • A Finite Sequences of Events
  • Functional Sequence Monoids
  • Finite State Machines

Question 3 : Compensating actions are run for:

  • All failed steps.
  • All incomplete steps.
  • All steps
  • All completed steps.

Question 4 : If a compensating action fails we:

  • Log an error and notify the Ops team.
  • Disregard that action and move on to the next.
  • Apply a different compensating action instead.
  • Retry the compensating action until it succeeds.

Question 5 : Compensating actions must be:

  • Derivative
  • Distributive
  • Associative
  • Idempotent

Question 6 : A timeout on a request means:

  • The request is queued.
  • The request succeeded.
  • The request failed.
  • All of the above.
  • None of the above.

Question 7 : Because of timeouts, compensating actions must also be:

  • Integral
  • Deductive
  • Communicative
  • Commutative

Question 8 : True or False: In the event of a timeout, we should run the corresponding compensating action.

  • True
  • False

Question 9 : Compensating actions are different from Rollbacks because:

  • A rollback assumes the original action is complete
  • A rollback happens after the original action
  • A rollback removes evidence of the original action
  • All of the above
  • None of the above

Question 10 : True or False: A big benefit to Sagas is the way they let us move forward when a failure occurs.

  • True
  • False

Question 11: The feature of Akka that supports the creation of Sagas is:

  • Akka Distributed Data
  • Akka Persistence Query
  • Akka Cluster Sharding
  • Akka Persistent FSM (Finite State Machine)

Case Study :- Sagas

Question 1 : In a previous exercise we described the scenario where a customer pays for the order and we must complete three separate steps. These steps included:

  • CollectPayment
  • CloseOrder
  • AwardLoyaltyPoints

The development team is experimenting with the idea of using a Saga to help encapsulate these steps. The following questions will address the implementation of that Saga.

Question 2 : One of the first things we will need to do, is determine appropriate compensating actions for each of the steps in the saga.

Think about the criteria that make up a good compensating action.

  • What happens if the compensating action gets handled twice?
  • Do we need to keep a history of the previous actions?
  • Is the compensating action “intent revealing”?

Question 2 : Which of the following would be the best compensating action for “CollectPayment”?

  • RollbackPayment – The log is rolled back to before the payment completed. Any items from the payment onward are removed.
  • DeletePayment – The existing payment is deleted. The original payment no longer appears in the log.
  • ApplyCredit – The customers account is credited for the amount of the payment. The original payment and credit appear in the log.
  • RefundPayment – The existing payment is refunded. The original payment and refund appear in the log.

Question 3 : Which of the following would be the best compensating action for “CloseOrder”?

  • OpenOrder – A new order is opened containing the details of the old order. Both old and new order appear in the log.
  • ReopenOrder – The existing order is re-opened. The close and re-open both appear in the log.
  • RollbackOrderClosed – The order is rolled back to a previous state. Any evidence that the order was closed is removed.
  • SetOrderAsOpen – A status on the order is changed from “closed” to “open”. The previous state is not maintained.

Question 4  :- Which of the following would be the best compensating action for “AwardLoyaltyPoints”?

  • DeductLoyaltyPoints – Loyalty points are deducted in the amount of award. The award and deduction both appear in the log.
  • CancelLoyaltyPointsAwarded – The award is cancelled. The original award, and the cancellation both appear in the log.
  • RollbackLoyaltyPoints – The loyalty points are rolled back to a specific point. Any changes after that point are removed from the log.
  • SetLoyaltyPoints – The loyalty points are set to a specific value. The original award, and the new value both appear in the log.

Question 5 :- As part of building this saga, we want to ensure that once we have the payment, we rarely, or never have to run the compensating action for “Complete Payment”.

In order to do this, “Complete Payment” should be:

  • Completed first
  • Completed second
  • Completed last
  • Completed in parallel with other actions

Question 6 : Assuming we have set up our Saga to perform the steps in the following order:

Close Order => Award Loyalty => Complete Payment

If we receive a timeout on the Award Loyalty step, which actions do we need to compensate for?

  • Close Order
  • Award Loyalty
  • Complete Payment

Note: Make sure you select all of the correct options—there may be more than one!

Question7 : If instead of a timeout, we receive a legitimate failure for the Award Loyalty (i.e. we can confirm that it failed), then which actions do we need to compensate for?

  • Close Order
  • Award Loyalty
  • Complete Payment

Note: Make sure you select all of the correct options—there may be more than one!

Question 8 : The saga solution we have provided is interesting, but it has some drawbacks.

Which of the following could be considered drawbacks of using the Saga solution in this case:-

  • A failure to close the order could result in us not collecting the payment.
  • A failure to award loyalty points could result in us not collecting the payment.
  • A failure collect payment means that we don’t award the loyalty points.
  • A failure collect payment means that we don’t close the order.

Chapter name : Messaging patterns

Two generals

Question 1 :The Two Generals Problem demonstrates:

  • That two phase commit protocols can not ensure consistency in a distributed system.
  • The impact of synchronous messages on a distributed system of at least two nodes.
  • That distributed transactions are brittle and prone to failure.
  • That it is impossible to reach a consensus over an unreliable communication channel.

Question 2 : The Two Generals problem is relevant to software where the unreliable communication channel is usually represented by:

  • The Disk
  • An Enterprise Service Bus
  • The Database
  • The Network

Question 3 : The messengers in the Two Generals Problem map to what concept in a Reactive System?

  • The Database
  • Microservices
  • Shared State
  • Messages (both synchronous and asynchronous)

Delivery guarantee:-

Question 1 : In order to guarantee message delivery we require:

  • A reliable communication channel.
  • An embedded tracking cookie.
  • An acknowledgement back from the receiver.
  • A chain of reliable postal workers.

Question 2 : True or False: One consequence of The Two Generals Problem is that due to potential loss of messengers, Exactly Once delivery of messages is impossible.

  • True
  • False

Question 3 : In a distributed system, we can have which of the following:

  • At Most Once Delivery
  • At Least Once Delivery
  • At Least Once Delivery with Deduplication
  • Exactly Once Delivery

Question 4 : When using At Most Once Delivery, if a message fails to be delivered we will:

  • Retry the message until it succeeds.
  • Retry the message at most once.
  • Retry the message more than once.
  • Lose the message.

Question 5 : At Most Once Delivery requires:

  • Message storage on the sender and receiver.
  • Message storage on the sender.
  • Message storage on the receiver.
  • No message storage.

Question 6 : When using At Least Once Delivery, if a message fails to be delivered we will:

  • Retry the message more than once.
  • Lose the message.
  • Retry the message at most once.
  • Retry the message until it succeeds.

Question 7 : At Least Once Delivery requires:

  • Message storage on the sender and receiver.
  • No message storage.
  • Message storage on the receiver.
  • Message storage on the sender.

Question 8: Exactly Once Delivery is impossible because:

  • Resending messages in the event of a failure results in duplication.
  • All networks are unreliable.
  • In the event of a timeout, we don’t know if the message was received or not.
  • All of the above
  • None of the above

Question 9 : Effectively Once Delivery relies on:

  • At Most Once Delivery
  • At Least Once Delivery
  • Exactly Once Delivery
  • Idempotence or Deduplication

Question 10 : Effectively Once Delivery requires:

  • Message storage on the receiver.
  • Message storage on the sender.
  • No message storage.
  • Message storage on the sender and receiver.

Question 11: The default delivery guarantee in Akka is:

  • Exactly Once
  • At Least Once
  • Effectively Once
  • At Most Once

Question 12: True or False: Once you start using At Least Once Delivery, you must use it everywhere.

  • True
  • False

Messaging patterns:-

Question1 : We can describe dependencies in a Point 2 Point system by saying:

  • Microservices depend on each other indirectly.
  • Microservices depend on an Enterprise Service Bus which links services indirectly.
  • Microservices depend directly on each other.
  • Microservices can claim their dependencies on their income tax.

Question 2 : Which of the following is true of a Point 2 Point system:

  • Dependencies are clearly defined.
  • Services are directly coupled to their dependencies.
  • Services have no direct knowledge of each other.
  • Dependencies are always managed using a service locator.
  • Complexity is hidden in abstraction layers.

Question 3 : Publish/Subscribe relies on some form of:

  • Enterprise Message Broker
  • Enterprise Service Bus
  • Command Broker
  • Message Bus

Question 4 : In a Publish/Subscribe system, messages are:

  • Sent to the message bus by a publisher
  • Sent to the message bus by a subscriber
  • Delivered to each subscriber by the message bus
  • Delivered to each publisher by the message bus
  • Delivered to only one place

Question 5 : True or False: When using Publish/Subscribe, microservices are not required to know about each other.

  • True
  • False

Question 6 : Which of the following are true about a Publish/Subscribe system?

  • Services are coupled to the message format and message bus, not to each other.
  • Coupling is high.
  • Complex dependencies can be hard to detect.
  • Indirect dependency allows for flexibility in how messages are provided or consumed.
  • Message formats must be rigidly defined and can not change over time.

Question 7: True or False: Distributed systems should be built using only point to point or publish/subscribe. You should never try to use both.

  • True
  • False

Question 8 : True or False: A Message Bus is just another name for an Enterprise Service Bus.

  • True
  • False

Question 9 : The responsibilities of a Message Bus in a Reactive System include:

  • Manage versioning of messages
  • Control deployment of services
  • Manage backpressure between services
  • Route messages to services
  • Provide exactly once delivery semantics

Question 10 : True or False: Akka and Lagom include facilities to support both Point to Point style messaging and Publish/Subscribe. Publish/Subscribe can be done with or without an external message bus.

  • True
  • False

Case Study :-

Question 1: In the Saga solution, which of the following messages are processed asynchronously (i.e. after the customer has left)?

  • CollectPayment
  • CloseOrder
  • AwardLoyaltyPoints
  • None of the Above

Question 2 : In the Message Driven solution, which of the following messages are processed asynchronously (i.e. after the customer has left)?

  • CollectPayment
  • CloseOrder
  • AwardLoyaltyPoints
  • None of the Above

Question 3: In the Saga solution, all of the messages are handled using the same delivery guarantee.

The delivery guarantee for the messages shown in the Saga solution is:

  • At Most Once
  • At Least Once
  • Exactly Once

Question 4: What delivery guarantee is most likely used when we send the “CollectPayment” message to the “Payments” service?

  • At Most Once
  • At Least Once
  • Exactly Once

Question 5 : What delivery guarantee is most likely used when we send the “PaymentCollected” message to the “Orders” service?

  • At Most Once
  • At Least Once
  • Exactly Once

Question 6: What delivery guarantee is most likely used when the “Orders” service sends the “CloseOrder” message back to itself?

  • At Most Once
  • At Least Once
  • Exactly Once

Question 7: Which of the following messages are delivered to the services using Point to Point?

  • CollectPayment
  • AwardLoyaltyPoints
  • CloseOrder
  • PaymentCollected (From the Message Bus to Loyalty and Orders)

Question 8 : Which of the following messages are delivered to the services using Publish/Subscribe?

  • CollectPayment
  • AwardLoyaltyPoints
  • CloseOrder
  • PaymentCollected (From the Message Bus to Loyalty and Orders)

Reactive Architecture: Distributed Messaging Patterns final exam answers:-

Question 1: Scalable Games is using which messaging pattern?

  • Scalable Games is an online gaming company. They have built a new game that they are hoping will have millions of users.
  • A key part of their infrastructure is the ability for users to manage lists of friends. Users can trade items with their friends, send them messages, and interact with those friends in the game. In order for this to work, friends need to know what each other is doing. One of the features they have is a notification service which will send popup notifications based on friend activities. This means that if a friend comes online then users will get a notification. Or if a friend wants to trade an item, they get a notification.
  • In order for this to work, certain types of events are sent to a centralized messaging platform. The notification service can then listen to these events and consume them in order to produce the desired popup.

Question 2 : Available advertising is using _______ messages to consume this data feed.

  • Available Advertising has built a pipeline to consume data from a variety of advertising networks. This data is then syndicated to a number of destinations through their Syndication Service.
  • Each of their advertising networks has a different way of obtaining the data. One network has them send a HTTP request for data. The network will then return a URL which they can use to obtain the requested data. Another HTTP request is sent to that URL which will return a portion of the data, and another URL if there is more to collect. They continue to consume each URL until they have obtained the entire data feed.

Question 3 : Saga Electronics can achieve what they are looking for by using which delivery guarantee?

  • Saga Electronics is an online retailer focusing on Electronics.
  • Their system has a Checkout Service, which is responsible for managing the final steps of the checkout process for a customer. Once the checkout has been completed, the information is sent on to the Fulfillment Service. This service manages the process of getting the product to the customer.
  • It is absolutely critical that the handover from the Checkout Service to the Fulfillment Service is successful. If for example, they attempted to send the order for fulfillment and it somehow got lost, then this would result in a customer who has paid for a product, but never received it. This kind of situation needs to be avoided at all costs.

Question 4 : Consistent Fitness is using what delivery guarantee for the messages to the server?

  • Consistent Fitness has built a microservice that receives data from their wearable fitness trackers. The fitness trackers will connect to the server and then upload whatever data has not currently been synced to the server. Once the data has been uploaded to the server, it can potentially be purged from the fitness tracker.
  • Sometimes the server is unavailable. When the server is unavailable any messages being sent to it fail. The fitness tracker doesn’t bother retrying those messages. Instead it simply gives up. The data is still stored on the fitness tracker and the next time we attempt to sync up with the server it will just upload then (including any new data received since). In that respect, it’s not critical that the server receive every message.

Question5 : Spectrum messages is making use of _______ Messages.

  • Spectrum Messages has a mobile application that provides instant messaging and chat features.
  • One feature of the Spectrum Messages application is that it allows users to see when their messages have been read. The way this works is that the original message is sent by the sender. This message may take some time to arrive on the receiver’s end, depending on whether the receiver is connected, whether there phone is turned on etc. Once the message is received, and opened, a notification is sent back to the original sender to indicate that the message was viewed.

Question 6  : Two Generals Video is using which messaging pattern?

  • Two Generals Video, a video streaming company, has built a platform for providing streaming video.
  • There system is made up of a number of different microservices. The Streaming Service handles the actual streaming of the videos. The Video Inventory service manages the list of videos they have available. They also have a Watch History service that manages the details about which videos have been watched by which users. Finally they have a Menu Service which manages the details about how to display the Menu for each user.
  • In order for the Menu service to operate, it needs a variety of different information. It needs a list of videos to display. To get that it makes a request to the Video Inventory service. At the same time they also need to filter videos based on what the user has already watched. To do that it makes a request to the Watch History service. It can then take that information and aggregate it to display the menu. Finally, once a user has decided what to watch, the Menu Service needs to make a request to the Streaming Service in order to begin streaming the video.

Question 7 : In order to ensure that both steps in the process succeed, or none of them do, CQRS Auto can leverage which pattern?

  • CQRS Auto is a automobile trading company formed in the 1980s by four partners (Christa, Quentin, Rhonda, and Samuel). They have since grown to be one of the largest auto traders in the nation.
  • Recently they partnered with ES Financial. This new partnership allows them to offer financing on vehicles purchased through their website. With this new setup, a user can log into the site, find a car that they like, setup financing, and purchase the vehicle, all at the same time.
  • The financing can take some time to go through. As a result sometimes the car they tried to purchase will be sold by the time the financing is complete. Or they may indicate they want to purchase the car, only to discover that the financing wasn’t approved. In either case if one thing fails they probably don’t want to proceed. They won’t want the financing if the car isn’t available, and they won’t want the car if they can’t get it financed.
  • financing if the car isn’t available, and they won’t want the car if they can’t get it financed.

About Machine Learning

Check Also

Python for Data Science Cognitive Class Exam Answers:-

Course Name:- Python for Data Science Module 1. Python Basics Question 1. What is the …

Leave a Reply

Your email address will not be published. Required fields are marked *