开发者

Recreate a graph that change in time

开发者 https://www.devze.com 2023-02-15 13:47 出处:网络
I have an entity in my domain that represent a city electrical network. Actually my model is an entity with a List that contains breakers, transformers, lines.

I have an entity in my domain that represent a city electrical network. Actually my model is an entity with a List that contains breakers, transformers, lines.

The network change every time a breaker is opened/closed, user can change connections etc...

In all examples of CQRS the EventStore is queried with Version and aggregateId.

Do you think I have to implement events only for the "network" aggregate or also for every "Connectable" item?

开发者_StackOverflow社区

In this case when I have to replay all events to get the "actual" status (based on a date) I can have near 10000-20000 events to process.

An Event modify one property or I need an Event that modify an object (containing all properties of the object)?


Theres always an exception to the rule but I think you need to have an event for every command handled in your domain. You can get around the problem of processing so many events by making use of Snapshots.

http://thinkbeforecoding.com/post/2010/02/25/Event-Sourcing-and-CQRS-Snapshots


I assume you mean currently your "connectable items" are part of the "network" aggregate and you are asking if they should be their own aggregate? That really depends on the nature of your system and problem and is more of a DDD issue than simple a CQRS one. However if the nature of your changes is typically to operate on the items independently of one another then then should probably be aggregate roots themselves. Regardless in order to answer that question we would need to know much more about the system you are modeling.

As for the challenge of replaying thousands of events, you certainly do not have to replay all your events for each command. Sure snapshotting is an option, but even better is caching the aggregate root objects in memory after they are first loaded to ensure that you do not have to source from events with each command (unless the system crashes, in which case you can rely on snapshots for quicker recovery though you may not need them with caching since you only pay the penalty of loading once).

Now if you are distributing this system across multiple hosts or threads there are some other issues to consider but I think that discussion is best left for another question or the forums.

Finally you asked (I think) can an event modify more than one property of the state of an object? Yes if that is what makes sense based on what that event represents. The idea of an event is simply that it represents a state change in the aggregate, however these events should also represent concepts that make sense to the business.

I hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消