I have a shared user repository (id, name, e-mail, password, etc.) exposed as a REST service - and multiple independent websites accessing this REST service (from the back-end) as a means of sharing a common user base across multiple sites.
I have a local, in-memory event bus (pub/sub) as part of the REST server implementation - it publishes events such as
UserDeleted, etc. which enables me to plug in new listeners that perform various actions, such as sending out notification e-mails, etc.
As part of the REST client implementation, I also have an event bus, with the same events, such as
UserDeleted, etc. - these events have the same shape and payload, but they don't have the same scope.
That is, if a user is created on site A, the
UserCreated event is triggered on client A, and when it accesses the REST API on the server, the
UserCreated event is triggered on the server, but the event, of course, does not occur on site B, and vice-versa.
If the events on the server and clients have the same shape and payload, and only differ in terms of scope, I can put these event implementations in a shared library and reuse them in the client and server implementations.
My concern is that, because event listener implementations would be interface-compatible, it might mislead other developers to expect that these events would also occur with the same frequency when plugged into the REST server or a REST client.
On the other hand, if they're compatible, I could write an e-mail notification listener once and plug it into the REST server, to send sign-up notifications to an admin - and plug the same implementation into REST clients, to send welcome e-mails to new users.
Is it okay to reuse these event implementations, even though they do not have the same scope?
Or should I duplicate the event implementations, in the REST client and server libraries respectively, to make sure other developers understand that the events, although identical in shape, do not have the same scope?
Bottom line, what defines an event? Is it defined by its shape and payload, or is it also defined by its scope, even though a change in scope produces no tangible difference in terms of shape or payload?