I was wondering what should be the granularity of the topic names in an event-driven service-oriented architecture.
Let's imagine we have a user management system where users can perform different actions like signing up, signing in, modifying some profile attributes, etc. If we wanted to notify the rest of the services of these changes, I can think of some possibilities for the topic naming:
One topic per each of the classic CRUD operations in each of the models (excluding read since the state of the user does not change). We would have
user-created
,user-updated
,user-deleted
. This approach is generic enough, but there would be potentially many services subscribed touser-updated
topic and discarding all those events that do not modify a specific field.One topic per business-relevant change. In addition to
user-created
anduser-deleted
, we could have events likeuser-email-updated
,user-signed-in
(which otherwise would be fired as auser-updated
event where the date of the last sign-in was changed), etc. My feeling is that even though it would be handy for those subscribers only interested in a very specific change, it would be harder for those services that need to sync whatever happens to the user, as they would have to be subscribed to an increasing number of topics to keep track of all the changes in the user model.A mix between 1 and 3, where both events
user-updated
anduser-email-updated
would be sent when the user updates the email, but justuser-updated
would be sent if the user changes the profile.