maybe my questions are more Event Sourcing/CQRS centric - however, since I’d really like to go for Event Store, I am going to post my questions below:
How would one typically do validation of Commands (especially creation commands) regarding unique key values?
For example let’s think of a simple system which is only responsible for User Management. So the User would be the aggregate root and the email address an unique field.
Inside the command handler for CreateNewUserCommand I’d like to do the validation if another user with the same email already exists (maybe the same user registered already some weeks ago and just forgot). If I understood everything right, the command handler would have to know about all registered users email addresses (in memory?) in order to do this validation. AFAIK it would be an architectural mis-design to query a read side component for this purpose or not?
Another open question is about integration with external systems. How would one insure that a specific notification about an event is only delivered once (just in case the external system can not handle idempotent calls)?
For example let’s stay in the creation of new users process and we’ve successfully validated the CreateNewUserCommand and firing a NewUserCreatedEvent. Some event listener would send a confirmation mail to the users email address and obviously I’d like to ensure that this mail is sent exactly once.
I would really appreciate it if there’s maybe a short sample using Event Store demonstrating these two scenarios which I think are quite common.
Thanks and regards,