Harry
Harry

Reputation: 73

EventSourcing for Aggregates that rely on other aggregates

I'm currently working on a calendar system written in an EventSource style. What I'm currently struggling with is how to create an event which create lots of smaller events and how to store the other events in a way which will allow them to be replayed.

For example I may trigger an CreateReminderSchedule which then triggers the construction of many smaller events such as CreateReminder.

{
  id:1
  description: "Clean room",
  weekdays:[5]
  start: 01.12.2018,
  end: 01.12.2018
  type: CREATEREMINDERSCHEDULE
}

This will then create loads of CreateReminder aggregates with different ids so you can edit the smaller ones i.e.

{
  id:2
  description: "Clean room"
  date: 07.12.2018
  type: CREATEREMINDER
  scheduleId: 1
}

So to me one problem is when I replay all the events the createReminderSchedule will then retrigger createReminderEvents which mean I'll have more reminders than needed during the replay.

Is the answer to remove the smaller events and just have one big create event listing all the ids of the reminders within the event like:

{
  id:1
  description: "Clean room",
  weekdays:[5]
  start: 01.12.2018,
  end: 01.12.2018
  type: CREATEREMINDERSCHEDULE
  reminderIds:[2,3,4,5,...]
}

But if i do this way then I won't have the base event for all my reminder aggregates.

Note the reminders must be aware of the reminderSchedule so I can later change the reminderSchedule to update all the reminders related to that reminderschedule

Upvotes: 0

Views: 66

Answers (1)

Andreas Zita
Andreas Zita

Reputation: 7580

Perhaps you are confusing events with commands. You could have a command that is processed to create your reminders (in the form of events, ie ReminderCreated) which is then applied to your aggregate to create your reminder-objects. This state is recreated in the same way every time you replay your events from its source.

Upvotes: 1

Related Questions