Command validation and external systems

Hi,

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,

Michael

http://codebetter.com/gregyoung/2010/08/12/eventual-consistency-and-set-validation/

"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."

In the example you gave it is impossible to make sending an email
only-once. You can only lower the probability of a duplicate to an
acceptable value. Email is not transactional sometimes email servers
themselves duplicate messages.

Hi Greg,

thanks for your fast answers!

Since I am developing in a JVM based environment my plan was to go for the HTTP based integration with Event Store. So if I got everything right, I have to provide the other technical buildings blocks for my application by myself like CommandHandler(s) (CommandBus/Router?), etc. right?

And each client subscribed to some event stream is responsible by itself to decide if it consumed already some event or not (this would be the answer to my email event handler question), right?

Thanks,

Michael

Well there is a jvm client as well. But atom can work perfectly well..

Over atom of course each subscriber remembers the last event it saw
(its handled by uri just like with rss or building a blog client, you
remember the last uri you processed). There is an example of this
logic here: http://docs.geteventstore.com/introduction/

I get a 503 on http://codebetter.com/gregyoung :slight_smile:

I don't run that site I emailed the people who do