2

I read some articles on event driven architecture. Every article says that generic events are bad practice. But I can imagine situations, where generic event may be handy.

For example I have 3 services. Reporting service, service A and B. Service A and B publishes events AProcessingFinished and BProcessingFinished. Reporting service is subscribed for those events and generates report.

Is it good design? If I add service C, then I would have to modify Reporting service in order to generate new report (subscribe for new event).

Wouldn't be better to have some generic event like ProcessingFinished? This way Reporting service would not be so closly coupled with other services.

bartek1965
  • 21
  • 2
  • From my point of view generic bullet usually not a great solution, in your case if you add another service I think another special report would be created, so any way you modify reporting service to generate new events? to resolve so abstract question you need to provide a more practical examples. – Dmytro Shabanov Dec 23 '19 at 12:14
  • Ok, so replace Reporting service with Mailing service. Would be better to keep mailing service generic and after each processing send command with email title, recipients and body? Or keep all emails (title, recipients, body) in Mailing service and send proper email when receive event (no email title, body, etc in event). – bartek1965 Dec 24 '19 at 11:11
  • It depends on your implementation and what are you using for email service if mail chimp for example are you need another abstraction over abstraction or not? And remember interface segregation principle here the more common implementation you do the less things you can make.So in real production I’m always try to reach as many as possible, generic things are great but it always limit you. – Dmytro Shabanov Dec 24 '19 at 11:39
  • There is no silver bullet here, in your case I rather create different event cause you can send various data from your micro services and sometimes it can be different – Dmytro Shabanov Dec 24 '19 at 11:41

1 Answers1

0

Events are about things that happened in your system. By it's nature it is in the past. UserCreated, SessionStarted etc. So it's specific things that happen in your system. Creating very generic events as you mention ProcessFinished is saying something like SomethingHappened in exaggeration.

I would suggest creating you events carefully about the thing that happened independent from the consumers of these events. So that every consumer can layout its own business logic without touching the event schema now and in the future.

Creating generic events just for the sake of merging certain events at consumer side will give headaches and problems in the mid/long term in my opinion. You should be able to consume various types of event to do business in your services easily.