0

In an event sourcing architecture, what is the typical pattern for passing information about related objects (aggregates)?

For example, in a order processing system, should OrderCreated event (published by the OrderService) contain productId or a Product?

Assuming there's also a ProductService), with the first option, receivers of the event can call the ProductService to get the Product and with the second option all the information it needs are already in the event. But I'm not quite clear on the pros and cons of the two approaches. Can someone shed some light?

0

Your productId is only a handle to the Product instance itself. This may or may not be useful on its own. For instance if you want to persist something to the database, and you require only the productId, then there is no need to provide also the entire Product instance.

That said, in all likelihood you probably will need the Product instance and all the data that comes with it. This complicates serialization of the event should you require it, but you'd need only to find a way to serialize the productId itself, which can be solved using a technical solution. Aside from this, there is no real reason why you wouldn't simply provide the Product instance itself. If the ProductService is required in other contexts, then you'd need both, otherwise the service is not necessary and can be removed. In other words, you don't have to pick between one or the other. If you require both ProductService as well as passing the instance of Product, then keep both.

  • Perhaps I wasn't clear. ProductService is not a property in the event, but a microservice which has an API that returns a Product given productId – ubi Feb 15 at 13:18
  • @ubi I had understood it this way. I didn't mean you'd need to pass both in the event. In a looser sense, I meant you don't have to get rid of the ProductService just because you pass a Product instance in your event (since you wouldn't need it for those requiring Product at least pertaining to that event). – Neil Feb 15 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.