Search code examples
microservicesevent-driven-design

Dashboard in Event driven design


Lets imagine we have several bounded contexts and they are all decoupled using messaging services (queues, message buses).

Some business process, lets say Order processing spans multiple bounded contexts.

For example, Order placed by the user is initially received, then validated, payment is processed, inventory adjusted, Order scheduled for delivery and finally Order gets into delivered state.

The EDA is implemented using choreography without central Manager.

Also, there is a dashboard which should, at each step, indicate the state of the order. Now, because of the async nature of the process, previous state event (e.g. PaymentProcessed) might get to Dashboard boundee context after next state (e.g. ScheduledForDelivery).

How to handle this situation where Dashboard should always reflect the last state of the process?


Solution

  • Apply the "never go back" principle. Let say that an Order has to go through the states state1, state2, state3 then state4. In your dashboard, put a little bit of logic to reject any message that would make an order to "go back". If you receive a state2 message for an Order that does not exist, create it in that state. If later you receive the state1 message for that same Order, reject it because you know state1 comes before state2.