From what I have read, CQRS designs involve asynchronous commands where commands are put in a queue. The user assumes all is okay and the UI polls or via a timer gets some feed back if all worked or not.
How would this work if I had a UI where I am dragging folders in a tree? I could have one user deleting a folder whilst another dragging a folder to it (to make it a sub folder of it).
So from the UI I could show the drag has taken place and then from in some timer check to see if my read model has be updated (i.e. check for the parent folder of the dragged folder and if it is set correctly I know it has worked).
If the user has done a number of drag operations, I would have to keep a list of these operations in the UI and check the read store (removing any successful commands from the list).
There maybe better ways to do this.
It just seems a lot of work on the UI and more prone to error whereas if I just run a synchronous command and if all is okay, then I move onto my next operation.
It's always in-sync. CQRS is rarely synchronous because we want to work/scale with different resources, type of databases, use a messaging infrastructure: we can rarely make a distributed transaction cross-resources (we could talk about XA or Sagas but… not now!).
An asynchronous command is a command that may not necessarily have achieved the expected result when control is returned to SA z/OS, as shown in Figure 1. Figure 1. Asynchronous Command Processing. User-supplied Completion Checking Routine.
While you can use synchronous commands, it will not make the problem you're describing any less of a problem; it will only mean slightly different behavior when notifying the user.
The thing to realize about commands is that they can be refused by the domain objects. What that might mean in this case is that the first user makes changes, and then the changes the second user makes may be rejected because they refer to an invalid state.
If you want to present the current state of the system to all users, your ui is going to have to do all of the work you're concerned about anyway; that's not at all unique to CQRS.
You can very well use synchronous commands. Asynchronous commands are not required for 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