My system uses The Command Pattern with separate handlers. My commands are executed on a CommandService which currently handles all commands in-process.
I have certain commands which do at least 1 of these things that are slow operations:
I want all of these commands to be handled out of process so that the UI is more snappy.
Should I use a messaging bus just for these commands, or should I have the in-process command handler call BeginInvoke()
?
The system has a small number of users (maybe 100 concurrent on a busy day), so the queue would likely never get very long. The main thing here is to reduce the amount of time the UI is blocked when sending an email with an attached PDF (the command in question). The employees have to execute that command many times in a day.
With the entire situation in mind, I think I'm going to go with BeginInvoke()
for now for several reasons:
But knowing what I know now, on a new system I would use a service bus from the get-go for any slow commands (virtually every system needs to send an email) and design the UI so that commands could more easily be switched from synchronous to asynchronous processing. In implementation, that basically means every POST is AJAX and performs an action in the UI as if it succeeded. (For an example of this, check out how Facebook handles comments.)
Both solutions has their pros and cons.
I'd recommend to estimate your system loading requirements, number of these background tasks, growing factor etc and depends on that to make a decision.
But in my personal opinion introducing a bus solution fitting @ 80% of cases. You can introduce a naive bus implementation that will be possible to extend on the next iterations if needed.