Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Providing synchronous behaviour in CQRS when needed?

I am using ASP.NET MVC with NServiceBus and where as the vast majority of commands can be executed with eventual consistency in mind, there are a small minority of tasks where immediate consistency would appear to simplify things.

I have done plenty of research on the various methods used to accomplish this but few come with any kind of justification as to why that particular method is preferable. I don't have any experience with NSB in a production environment, so it would also be nice to know if any methods limit scalability in any way.

The following are broadly the methods I have come across: -

  • No synchronisation, fake the information back to the client. My reservations with this one are firstly, you have to deal with the case where you have faked the data and the command has failed (unlikely scenario) and more importantly, if the initialisation of any data within the command is complex, the ability to fake this data is not necessarily feasible anyway.
  • Reply (or publish event to be recieved by client) when the task is completed. My reservation with this one is that it means that the distributed architecture becomes more complex and I am not sure if load balanced clients would cause issues as only one of the client machines should be recieving the reply.
  • Poll the read store until data is present. My reservation with this one is that it puts the read store under more load than the other options.

Are there any options which are better than the above three and if so, why? If not, which of the above three are better and why?

I am assuming that the answer is not subjective and one suits using NServiceBus to implement the command infrastructure in CQRS better than the others.

Thanks.

like image 380
user1085351 Avatar asked Nov 13 '22 00:11

user1085351


1 Answers

My take on this is that the actual endpoint should not be performing the work but be handing it off to some 'Task' (Application Service / Operation Script) object. That object is performing the work immediately.

So for cases where you absolutely have to have 100% consistency rather call that same task object rather than sending a command for later processing. You may still want that command for other scenarios.

like image 113
Eben Roux Avatar answered Nov 15 '22 08:11

Eben Roux