froi
froi

Reputation: 7768

Is it critical to persist published events on an event driven system?

Using the example here as a case: https://microservices.io/patterns/data/event-driven-architecture.html

Assuming the system is not using Event Sourcing at all. But rather events are just a means to trigger something.

Does OrderService need to persist somewhere that OrderCreated event was published?

My thought was, when investigating/tracing the state of things, it would be hard to know if an event was actually published at certain points in time.

How is that usually dealt?

Upvotes: 0

Views: 310

Answers (1)

Edwin Dalorzo
Edwin Dalorzo

Reputation: 78589

I have implemented an event-driven system around orders before, and in my opinion, the order needs to be persisted before you broadcast the OrderCreated event.

The order can be persisted in a status that reveals that it is pending and waiting for authorizations or payments. At this point, the order is not available for fulfillment (i.e. shipment creation), it just there waiting for the process to complete.

The order may still appear in some user interfaces though. For example, the Fraud/Payments team may be interested in the size of the queue of pending of authorization orders, and of course, if the order fails to get authorized for any reason, the Fraud Team may want to review it to determine what is going on and potentially put it in a status that makes it available to a customer service representative to call the client to fix any issues, e.g. change the payment method.

So, the order is like a state machine, moving from one state to the other, until it reaches a final state (e.g. canceled, fraud, shipped, etc).

That's why I definitively believe the order is probably safer if it is saved in a database and the different events make sure the order makes progress.

Perhaps that's why Chris Richardson suggests the use of Saga to control this state machine instead, and that way you would have a centralized point to control the flow. However, I believe it is also possible to do it solely using events, it is just a bit trickier to control the entire flow.

Upvotes: 1

Related Questions