I have an Event Sourced system that has 3 micro services (simplified):
- User management - Registering a user, change password etc
- User account - manages debiting/crediting of the user account balance
- Notifications - email notifications when balance changes
I have a requirement that we want to have Demo users that can use an app like any other user but we don't want to send any notifications to them.
Of course this is an example but you can see how other services can also have different behaviour based on this fact (demo or not).
I'd like to ask you what can be the best option to implement this. Of course it might be that i've got the micro services part wrong.
Potential Implementation 1
- When registering user i send
demoflag within event so it looks like this:
- I listen for this event in
Notificationsservice and then decide to add the users without
demoflag to it's internal store
- Then when
Notificationsservice listens to
AccountBalanceDebited(user, debit)event it just ignores the ones for user it does not have in internal store
Drawback is that i might end up adding more stuff to
Potential Implementation 2
- When registering user i create either
- I listen for
UserRegisteredevent only in my
AccountBalanceDebitedevent i check whether we have user recorded (same as in Potential Implementation 1)
Drawback is that we have a lot of common behaviour for user and demo user so we need to listen for both events in most cases.
Potential Implementation 3
- When registering users i create
UserRegistered(email)event and if this is demo user then i create
Notificationsservice i listen to both events, on
UserDemoModeActivatedi just remove user record from internal store and proceed as in previous implementations
Implementation that i don't want to use
Notifications service get the User entity (basically shared model) and check demo flag here.
The more i think of it the more i'm into 3rd solution and what i like about it is that it is more an addition than a change in the system.
This is my first approach to ES so i would be glad to get help with it.