hopefully this is the right place to discuss a general architectural question.
I try to see my software system as a alternating sequence of view model compositions and commmand executions. Due to the distritubted nature of NSB systems in each operation (vm composition and command execution) there are mutliple services involved. This works well for cases where the data for the composition is already present in the service and a command execution adds or manipulates data that is then visible in the next view model composition.
As an example consider adding a position to the basket: i do a view model composition, the basket is empty. I issue the command to add something to the basket. Several services work independently an create their own data, for example one services reminds that the position is in the basket, one services adds availability information and another services calulates the price. In the next composition all these services add their respective information to the basket position and the basket is rendered with all information being tied togehter.
But I also have a cases where the data is not already present in a service when the first composition starts, becuase there does not seem to be a natural trigger for generating it. In that case when the composition starts we notice that there is no data and we then need to issue a command in turn of the composition, wait for this command to finish (ugh) and then return the data.
I will give an example for this too. Take a webshop where every customer gets specific prices for all of your many articles depending on a lot of parameters. Say you have 10000 articles and a customer gets a different price depending on the date, the time, a group and the fact wehter he ordered today already (so he might get a different price on a second order on the same day). All these parameters can easily be evaluated once a single positon is added to the basket, because the service that calculates the prices konws all the invariants. But the customer wants to see a list of products with the prices he will have to pay attached. If I have as little as 1000 customers given I have four parameters (date, time, number of same day orders, group) how can I compute all possible prices in advance? As we know “Batch jobs” are flawed and I simply do not know what prices to calculate in advance because I do not know when and how often the customer will order a specific product in a day.
There does not seem to be a good “command” that I can issue to start calculating the prices. Something like “ShowArticlePage” does not seem to be a proper command. And even if I would go with it, the command would be issued in the same moment as the customer expects the result - so the user really requests a composition. But the data for the composition needs to be “Created on demand”. But that does not seem to be a good fit for executing a command because commands should be executed purely asynchronous.
One solution would probably be to use WebSockets or something to update the prices once the calculation is done in an asynchronus manner. But we encounterd problems with it with some customers that could somehow not establish a web socket connection. So this seems to be risky as well. Polling would eventually create a lot of load to the system. Another possibility I already thought of is to just calculate the prices for a page on the fly, so not issuing a command so that the calculated prices are only used for display and not being stored at all. But that would be a hit to performance because the prices will be recalculated every time I switch throuhg the pages.
I hope I have explained my problem in an understandable way. I am really a little stuck here and I do not know how to handle the situation properly. Any thoughts are welcom.