.netparallel-processingmasstransitsagaautomatonymous

Parallelism with MassTransit saga and compensation


I have some queries since I am new to the MassTransit saga.

Queries:

  1. Is it feasible to introduce parallelism with MassTransit saga?
  2. If so what is the proper way?
  3. If so what about the compensation mechanism?

Scenario:

Let's take an example of food delivery.

  1. pack cookies
    • unpack cookies
  2. pack tea
    • unpack tea
  3. wrap both in a good package.
    • unwrap
  4. complete the order
    • Cancel order

Let's assume I want to perform actions 1 and 2 parallelly and then 3 and finally 4.

** What could be the better way to do actions 1 and 2 parallelly keeping the compensation mechanism in mind?

N.B.

masstransit-discuss thread link) from this thread, maybe I can perform actions 1 and 2 parallelly with the composite event. If I do this way then how to handle the compensation in case of failure of any one of the actions 1 or 2?


Solution

  • MassTransit sagas (state machine or otherwise) do not support compensation. If the saga orchestrates consumers and/or processes events, the state of those consumers is the responsibility of the developer to track. In the event that subsequent events/behaviors are unsuccessful and compensation of previous behaviors is necessary, that's up to the developer.

    If you truly need a distribution transaction behavior using MassTransit, you should be using Courier which is a routing slip implementation with compensation.