mardi 6 décembre 2016

CQRS and commands debouncing

I have the following task:

  1. Our current architecture is Web SPA with CQRS and MVVM. We have commands, queries and SingnalR as message bus.
  2. Users can select, move, resize divs on the same workspace from several web browsers simultaneously.
  3. Each div is binded to the approprite ViewModel. Each ViewModel has it's own query to refresh. Each ViewModel subscribed to business events and refresh the whole state after it.

Lets image that User is doing the following steps:

  1. Select div (SelectWidgetCommand sent)
  2. Move div to x=10. (ChangePositionCommand sent)
  3. Move div to x=100. (ChangePositionCommand sent)

The problem is that the commands are fire-and-forget and the User may receive event WidgetSelectedEvent during the Step 3 but the ChangePositionCommand may not be handled yet. So the User will receive the old x position and the div will move to the old position.

What is the best practice to handle this kind of issues?

What we are now doing is splitting the DivViewModel into two divs: SelectionViewModel, PositionViewModel. Each ViewModel has it's own query to refresh and different events to handle. Also we consider using debounce and rolling buffer for commands handling.

Aucun commentaire:

Enregistrer un commentaire