So far, we have reviewed many special details about I/O-bound tasks, but what about CPU-bound work? Technically, the most efficient way will be to run such work synchronously and scale horizontally by adding more and more servers to be able to handle increasing load. Nevertheless, it can happen that this CPU-bound work is not the only responsibility of a server application. In this case, we can find a way to get this to work out of the web application, allowing it to run fast; now the CPU-bound part can be scaled separately and does not affect the rest of this application.
This is how cloud applications work. Usually, if there is a long running operation, a web application registers it into some data store, returns a unique identifier of this operation to the client, and posts this operation to a special queue. Then there is a separate pool of worker processes that monitor this queue, get tasks from them, process them, and write results to a data store. When the...