1

We have an aggregate called SignupRequest and we need to keep track this aggregate history e.g. The Request is accepted or banned or something like that. Which solution you prefer to model these business concepts?? 1- We create a signupRequestHistory aggregate that is used to manage the history of the signupRequest?? 2- The SignupRequest will contain a collection of SignupRequestHistory value object.

  • keep in mind that the SignupRequestHistory is just a tracking history(immutable data) for the request itself. No business invariants exist for these history data
  • Also, the same concept applied in many places:- example, Subscriber and SubscriberHistory so, we need a clean pattern do implement that functionality
  • Also, The history will be just for reporting purposes
1

2 Answers 2

3

As you mentioned, you could create a SignupRequestHistory aggregate which holds the status of the SignupRequest and the date/time of the change.

The SignupRequest will contain a collection of SignupRequestHistory value object.

Before adding collections to your SignupRequest you need to think of why you are doing it. You specified "no business invariants exist" which is the first indication the SignupRequest probably does not need a collection of SignupRequestHistory.

I don't know your exact domain but SignupRequestHistory is probably not really part of it. It is not used to solve any business problem and is strictly for reporting/visual needs. What SignupRequestHistory really represents is a domain event - a change of state in your domain. This leads me to believe you would benefit from Event Sourcing.

When using Event Sourcing all domain events an aggregate root raises are stored in sequence in an event store. Anytime the state of an aggregate is altered an event is raised which gets stored for future use. This gives you a history of all the different states an aggregate root was in. You can reconstruct the aggregate root by reading the events in sequence(an event stream) from the event store to any date/time in history to see what the aggregate root looked like at that time in history.

For reporting needs you can construct highly efficient view models using the various stored domain events.

Event Sourcing can be a lot of work up front. If you don't have a lot of time maybe going with the first approach is best. There are pros and cons to each method. You should definitely look into Event Sourcing in your spare time though.

4
  • @ConstantinGALBENU That's pretty much what I said minus the "another Bounded context". Having another BC just for this could also be considered "too much overhead". We don't know OPs exact domain and his/her circumstances so only he/she knows what is plausible.
    – daviomey
    Apr 20, 2017 at 17:59
  • I've deleted the comment Apr 20, 2017 at 18:02
  • Event Sourcing indeed requires some work but it is not wasted since the one who builds an event sourcing framework herself usually gets knowledge about it. In a longer run, event sourced applications are easier to maintain due to the audit log of events but migrations are a bit harder. Apr 21, 2017 at 20:24
  • Thanks for your help. I will choose the first approach for time being but in future, we will consider the Event Sourcing approach
    – roro2012
    Apr 23, 2017 at 9:26
3

I suggest to refine your bounded contexts boundaries once again, maybe this history should be kept in another bounded context.

You could try to use CQRS and create a specific read-model that contain the history of all aggregate states by listening to the relevant domain events emited by the write-model (the aggregate).

Although Event sourcing is great it is not suitable for this situation. It has too much overhead just to benefit from an entity history.

UPDATE

Event sourcing has two main advantages over plain CQRS:

  1. you do not need to use transactions
  2. you could latter add as many read-models as you wish

It also have a big minus:

  1. Event versioning

It is your call if any of the two advantages would help you in your application.

5
  • I think it's important to state that full-fledge event sourcing is not required to publish and store domain events. A hybrid approach between storing the current state and use some events for history tracking purposes may be used.
    – plalx
    Apr 22, 2017 at 0:35
  • @plalx I added an explanation about ES Apr 22, 2017 at 1:10
  • Thanks for your help. but creating another BC for the history will be excessive for us, at least for time being. Also, We don't have time to create Event Sourcing so, we choose a simple solution by creating a simple SignupRequestHistory aggregate and this aggregate will contain the history data :)
    – roro2012
    Apr 23, 2017 at 9:31
  • 1
    I think your history should be just just a projection/readmodel, and not an aggregate. It has no invariants to protect. Apr 23, 2017 at 9:48
  • Or just a simple CRUD entity that wraps a SignupRequest Apr 23, 2017 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.