Search code examples
commandcqrsbrighter

CQRS - Command Store persisting rule


I have been using the Paramore Brigther to implement CQRS and its Command Store. My question is:

What would the best practice be, is it storing the command before or after the handling method completed? I read here it recommend to do it before but don't we want to not storing the command if the handler fails ?

However i can think of few scenarios where you wish to store the command before/after the hendler method executed:

Case A. if there is IncreaseCreditLimitCommand, and during customer retrieval, customer not found. IMO, we do not want to store this command, do we ?

Case B. if there is IncreaseCreditLimitCommand, and during business validation the customer being denied to increase the limit. IMO, we still want to store this command, don't we?


Solution

  • What would the best practice be, is it storing the command before or after the handling method completed? I read here it recommend to do it before but don't we want to not storing the command if the handler fails ?

    Why not? If we want to be able to reproduce what happened later, then we also need to be able to reproduce the commands that fail.

    The various write ups of the LMAX Disruptor are good reading to do if you are considering a design where persistence of commands is a feature.