Search code examples
microservicesmessage-queue

specific or abstract when issuing a event in MSA?


We have blog service that can update the title of the blog.
And we have search service that allows you to search for blog title.

In this system, when blog title changed, search service should put the blog title to search engine

I am trying to implement this requirement using a message system.

The blog service should issue event when the title is updated. There seem to be two options.

  1. Specific. issue BlogTitleUpdatedEvent with blogId and title
  2. Abstract. BlogUpdatedEvent with blogId

First option is specific, It is clear what event occurred but each time another event is added, we need to create one.

Second option is abstract, so blog service not dependent on other services. because we don't have to know what other service doing. we just issue blog update event. but other service should be request data for each requirement

When we try to build message system in MSA, which one would be better? I would appreciate it If you could tell me about your experience.


Solution

  • Related Stackoverflow blog.

    You could send both events, but the answer comes down to what you need to consume, and how you plan on using those events.

    Ideally, you'd include the title (and other metadata) in the event. Otherwise, you would only know something was updated for that blog. Then you need to query for that blog, and parse everything and perform a diff to see what actually changed (or do a whole document overwrite in your search index).

    If you send exactly what is changed, you would reduce the load on the search service / indexer, and save yourself a lookup query to the blog service.