I recently encountered a microservice architecture with 50+ services communicating with messaging using publish/subscribe on a topic. I have previously worked with event based systems where each service creates and dispatches its own event, so I was suprised when I realized this(theese) system(s) were actually sharing a lot of message types.
Here's a short example from a fictional book store.
Message publishers
- The owner can publish new Book messages from the OwnerService.
- Publishers can publish new Book messages from the PublishersService.
- Writers can publish new Book messages from the WritersService.
- The ShelfService can publish BookPlacement messages
- The BookPriceService can publish BookPrice messages
Message subscribers
- The OwnerService listens for Book messages
- BookPriceService listens for Book and Price messages
- The ShelfService listens for Book messages to add to the shelf
- The SearchService listens for BookMessages, BookPlacement and BookPrice messages
To me, this seems like the messages being re-used are causing a few issues.
Each service persists all of the data in the messages they receive. Not only the data that service is interested in.
There are also dependencies within the services that require the messages to be received in a certain order. I.e. the BookPriceService requires a Book message before the Price message or the Price message is discarded.
Is it a design smell where multiple message publishers share the same message type? Would it be preferred to have each service publish its own message type?
Perhaps needless to say but all messages share the same Topic and are separated by message-type filters.