eventsource icon indicating copy to clipboard operation
eventsource copied to clipboard

Question about Aggregate Validation

Open xujihui1985 opened this issue 7 years ago • 2 comments

I have a question about event-sourcing, how can we validate if the Aggregate can be persisted? Like the example that create a User, how to validate that user has already exists? To restore all the aggregate from event is to expensive. And just check usercreatedevent is also not enough, because user maybe change the username or be deleted. hope you can shed some light on it

xujihui1985 avatar Oct 12 '17 02:10 xujihui1985

Global validations are particularly difficult for event sourcing systems. If you listen to Greg Young's talk, he suggests that you don't really need to do global validation.

That said, we came across the same issue. The way we solved it is in the single package, github.com/altairsix/eventsource/singleton.

Commands that need to guarantee some uniqueness implement singleton.Interface. The singleton package uses a separate dynamodb table to manage the uniqueness of resources.

It could use better documentation, but the general pattern is:

  1. create dynamodb table (pre-requisite)
  2. create event source registry
  3. create singleton instance
  4. using singleton.Registry#Wrap to wrap the Dispatch function

One of the test cases in https://github.com/altairsix/eventsource/blob/master/singleton/singleton_test.go provides an example of how the singleton is used.

savaki avatar Oct 26 '17 23:10 savaki

@savaki thanks for the reply, I will have a look at the example

xujihui1985 avatar Oct 27 '17 07:10 xujihui1985