Should commands be asynchronous in CQRS?

From what I read, CQRS projects include asynchronous commands, where commands are queued. The user assumes that everything is in order, and polls of the user interface or through the timer return some channels if everything works or not.

How does it work if I had a user interface where I drag and drop folders into a tree? I can have one user deleting a folder, and another - dragging a folder into it (to make it a subfolder).

So, from the user interface, I can show that the drag was done, and then use some timer to check whether my reading model is updated (i.e. check the parent folder of the folder being dragged and if it is installed correctly, I know it worked).

If the user performed several drag and drop operations, I would need to save the list of these operations in the user interface and check the read repository (removing any successful commands from the list).

There may be better ways to do this.

It seems that most of the work with the user interface is more error prone, whereas if I just run the synchronous command, and if everything is in order, then I proceed to the next operation.

+6
source share
2 answers

While you can use synchronous commands, this will not cause problems that you describe as few problems as possible; when notifying the user, this will mean slightly different behavior.

The thing about implementing commands is that domain objects can be denied. In this case, this may mean that the first user makes changes, and then the changes made by the second user can be rejected, because they relate to an invalid state.

If you want to present the current state of the system to all users, your ui will have to do all the work you are worried about anyway; which is not unique to CQRS.

+5
source

You can very well use synchronous commands. Asynchronous commands are not required for CQRS.

+3
source

Source: https://habr.com/ru/post/918867/


All Articles