We are considering integrating messaging (publishing events) in our system, we multiple components, a few different stacks etc.. We’ll start with a small number of publishers and subscribers and gradually introduce where it makes sense.
If we publish an event, say type: ‘NewProductAddedToCatalogue’, should it included all the attributes of the new product or just the new product Id or some form of rest url perhaps e.g. http://db.intranet/products/%5Buuid%5D. What are the advantages of each approach? I feel some subscribers would just be interested in a minimal number of attributes whilst others e.g. website publisher might want access to them all (or most). Are there any significant downside to either approach?
The quick answer – why not publish two types of event message?
One could be a lightweight event with just the product ID and this would be used by subscribers who would then enrich the event data themselves.
The other message would contain all the data needed to make sense of the event, for consumers who didn’t want to enrich the data.
The longer answer – I don’t really like the “lightweight” event idea. The problem with this is that you are basically turning your event message into a “something changed” notification.
This removes the event from it’s underlying data change – for example a notification does not say what has changed, but only that something has changed. It’s entirely possible that the event message may have been delayed to the point where the underlying data is no longer in the same state as it was when the event was raised (whether this is a problem for you is down to your individual requirement).
More importantly however, the lookup to “enrich” the data introduces coupling between components – the idea behind an event message is that the event subscriber can just process it – the subscriber doesn’t need to know anything about the publisher of the message – or, more specifically, about the data source that the message came from.
However, there are some benefits – notification-type message processing is idempotent by nature so there’s less effort involved there.