Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single or multiple topic (stream) per Aggregate Root event in kafka

My Order aggregate root is able to emit several Event, e.g. OrderCreated, OrderPaid, OrderCancelled. Would it be good design to store all types of order event into single kafka topic and to have the orderId as the message key, as suggested here? Or Should I create sepparate topic for each of them?

The pro of having single topic is that the order of events is maintained, but consumer would need to filter some events on their end. The pro of second approach is consumer would be simpler as they can subscribe to the exact topic that they need, but constructing Order requires subscribing to multiple topic while they don't come from kafka in the right sequence as they are from different topics.

Thank you

like image 979
Fajarmf Avatar asked Oct 15 '15 22:10

Fajarmf


1 Answers

I am not sure if there is a right/wrong question, however here are my two pennies' worth of it:

  • My rule-of-thumb is a topic for each bounded context to strike a balance between ease of management and amount of events received by the listeners
  • Events need to be sequenced anyway, so that they are stored in the EventStore in the right sequence. Add a sequenceId to your event and use a Resequencer (e.g. in Camel) to make sure that a listener processes events in the right order.

Hope that helps and good look with your project.

like image 126
Alessandro Santini Avatar answered Oct 06 '22 15:10

Alessandro Santini