Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about Aggregate Validation #12

Open
xujihui1985 opened this issue Oct 12, 2017 · 2 comments
Open

Question about Aggregate Validation #12

xujihui1985 opened this issue Oct 12, 2017 · 2 comments

Comments

@xujihui1985
Copy link

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

@savaki
Copy link
Contributor

savaki commented Oct 26, 2017

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.

@xujihui1985
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants