0

Let's say we have a ecommerce platform. When user create order - we should make several actions like

  • Send push to client
  • Send push to custome
  • Send emails
  • e.t.c

Generally I see two diffrent aproaches to arrange it. Is there some more right way to do it?

First:

In orderController Push One message "createOrder" to MQ: then dedicated handler will split this message to few messages like (pushOrderMessageToClient, pushOrderMessageToCustomer and etc) and push them to Message queue.

Second:

In orderController push few messages like (pushOrderMessageToClient, pushOrderMessageToCustomer and etc) without one general "createOrder" event

4
  • 2
    Or #3. OrderControll is agnostic to whatever comes after an order is created or processed. It just notifies the entry of a new order. Others will handle this and do their job, for example, by pushing notifications. Event Driven is all about eventual consistency. The fact that you are thinking about chaining events should rise a red flag on how you are approaching this sort of thing. It might help to think of this as a choreography of events rather than a sequence of events.
    – Laiv
    Commented Nov 17, 2022 at 9:28
  • @Laiv but how Others will know about a fact that order was created?
    – Ilya
    Commented Nov 17, 2022 at 9:33
  • 2
    Because you will broadcast the event through, say a queue or stream. Other participants of the architecture will listen to these events but only react to very specific ones. This can happen within the boundary of a single application (something I don't recomend) or it can span multiple systems. It depends on what kind of architecture you have.
    – Laiv
    Commented Nov 17, 2022 at 9:48
  • Laiv has the right approach. Think of it as having commands and events. A command is something like CreateOrder and an event is something like OrderCreated. Commands are only handled by one subscriber and once the order is created it raises the OrderCreated event which may have many subscribers. What is done by the subscribers of the OrderCreated event is no concern with the process that creates the order. Commented Nov 17, 2022 at 14:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.