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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With