Event Sourcing and Read Model generation

Personally I think there’s nothing wrong with looking up the user’s name from within the event handler. But if you’re in a position where you can’t query the name from the User’s read model then I’d introduce an additional event handler to QuestionEventsHandler, to handle the UserRegistered event.

That way the QuestionEventsHandler could maintain its own repository of user names (you wouldn’t need to store the users email). The QuestionAsked handler can then query the user’s name direct from it’s own repository (as Rinat Abdullin said storage is cheap!).

Besides since your QuestionItem read model holds the user’s name, you would need to handle the UserNameChanged event within the QuestionEventsHandler as well to ensure the name field within the QuestionItem is up-to-date.

To me this seems less effort than ‘enriching the events’ and has the benefit of not building dependencies on other parts of the system and their read models.

Leave a Comment