Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CQRS Validation & uniqueness

In my CQRS architecture, I'd like to validate that when I send a InsertSettingCommand (setting is a key/value object), I want to check that the key doesn't already exist in my database. If I understand CQRS & validation well, it says that the validation should be performed in client side only when it's about verifying some formatting stuffs like checking that email respects some syntax or that customer's name is not empty. But in my case, I need to query my database to see if it exists, but I don't know if it's correct to query my read store in client-side ? Or should I call my read store in my domain side ? Then throws an InsertSettingDuplicated event ?

So what's the best approch to take in my situation in a CQRS environment? Some people talk about compensating actions ? Is it something that can helps me ?

Thanks.

like image 577
John Avatar asked May 26 '11 14:05

John


1 Answers

It is ok to make query from client side to read storage in order to validate uniqueness. Here is some thoughts from Greg Young about set based validation using CQRS.

like image 106
xelibrion Avatar answered Oct 01 '22 15:10

xelibrion