I am working in an event-sourcing architecture and while creating the aggregates I came to an interesting challenge, disclaimer I'm new to this.
I have a UserAggregate encapsulating the logic for commands, the user has a relationship with campaigns but not really owned by user.
Campaigns are created by an admin system, users can accept to participate in campaign. In my understanding there are boundaries between Campaigns and Users and so will be two different services.
UserAggregate contains IEnumerable<AcceptedCampaign>
property and a command can be void AcceptCampaign(campaignId)
which creates an object AcceptedCampaign
and sets the AcceptedCampaign.Status = Accepted
and raise an event of UserCampaignStatusChanged
.
An admin related listener is registered to this event, loads a CampaignAggregate and the admin (human) changes the status of the campaign based on additional event data and raise the event UserAcceptedCampaignStatusAdminChanged
.
There's a user related listener now subscribed to the UserAcceptedCampaignStatusAdminChanged
event and will change the UserAggregate with the new status using void ChangeCampaignStatus(campaignId, status)
which sets the AcceptedCampaign.Status = Approved
and raise an event of UserCampaignStatusChanged
though and brings us to a cycle between admin <> user listeners but with a relatively easy solution.
My thoughts now are the below.
- Admin listener will only process
UserCampaignStatusChanged
with status that is of interest of admin but feels a bit error prone e.g.switch (campaignStatus)
; - Is it OK for UserAggregate to be shared between the microservice and an event subscriber of
UserAcceptedCampaignStatusAdminChanged
or it breaks Single Responsibility?
I appreciate your input.