I have a project with the CQRS & Event Sourcing already implemented. Now I am going to implement a Read Model.
At the moment, the ProductCreated event has the EventID and the Product ID. But we for the read model, I want to use different fields - Product Name and category.
In this case, do I need to add the Product Name & category to the ProductCreated event, or create another event with only the name & category for the Read Model?
I am new to CQRS & Event Sourcing. I've spent the whole day finding an answer for this question, but couldn't find a proper solution.
Thanks in advance.
Simply
If you have a dedicated read model it should definitely have the ProductID as well as the ProductName and Category.
Why?
Simply because if someone request this model lets say some Client UI or API client without the Id it will not be able to track down which exact Product is the one you have returned as the ProductName could be the same for multiple Products.
In this case, do I need to add the Product Name & category to the ProductCreated event, or create another event with only the name & category for the Read Model?
Guessing from the naming ProductCreated event is an event holding the information that the Product has been created. It depends really on your business needs and your design but I would suggest putting all Product model information(at least the properties that should be public) in the ProductCreated event. This would be ProductId, ProductName, ProductCategory and some others( if you have something like ProductDescription, ProductCode and whatever is in the model of Product).
Whoever is listening to this event could that decide if they want to save the whole model in their storage or just a subset of that model. This is of course based on need of that particular event consumer.
This approach is good if you have or will in future have multiple consumers of the Event you publish. If not and you have only 1 then you can remove the properties which you don't need in the read model.
Conclusion
You don't need a second event for transferring a subset of data as you described. I would suggest to put everything to the ProductCreated event and then in your read model while handling this event save only the subset of data that you need there.