Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How granular should a domain event be?

I am wondering how granular should a domain event be?

For example I have something simple, like changing the firstName, the secondName and the email address on a profile page. Should I have 3 different domain events or just a single one?

By coarse grained domain events when I add a new feature, I have to create a new version of the event, so I have to add a new event type, or store event versions in the event storage. By fine grained domain events I don't have these problems, but I have too many small classes. What do you think, what is the best practice in this case?

like image 820
inf3rno Avatar asked May 23 '14 15:05

inf3rno


People also ask

What is domain event DDD?

In domain-driven design, domain events are described as something that happens in the domain and is important to domain experts. Such events typically occur regardless of whether or to what extent the domain is implemented in a software system. They are also independent of technologies.

How do you raise a domain event?

The deferred approach to raise and dispatch events Instead of dispatching to a domain event handler immediately, a better approach is to add the domain events to a collection and then to dispatch those domain events right before or right after committing the transaction (as with SaveChanges in EF).

What is the difference between event sourcing and event driven?

To be clear, Event Sourcing is about using events to represent state. In Event Driven Architecture, events are used to communicate with other service boundaries.


1 Answers

What's the problem with many classes? Really, why so many devs are afraid of having too many classes? You define as many classes as needed.

A domain event signals that the domain changed in a certain way. It should contain all the relevant information and it should be taken into consideration the fact that an event is also a DTO. You want clear events but it's up to the developer to decide how granular or generic an event is.

Size is not a concern, however if your event 'weights' 1 MB maybe you have a problem. And the number of classes is not a domain event design criteria.

like image 84
MikeSW Avatar answered Oct 08 '22 18:10

MikeSW