Moving towards event based programming from monolithic
To increase responsiveness, many strategies are followed. For example, moving towards micro-services, dividing load between different servers for different nodes etc.
There is also an option to use event based programming. By dividing single monolithic flow to set of small tasks which works in different specified area (thread pool).
I am in this article, trying to express my views on event based programming. We can consider taking input from the request and add this input to a queue. This input is then processed and further added to different queues for further processing.
For example, if we have a flow where a person record update is required and this person record is highly complex object. We can add input (json) to queue to be consumed by processor. The processor instead of calling each section update, it just extract info for section and add it to respective section queue.
So, it is like
-----------------------------------------------------------------------------------------------------------------------------
REQUEST---->Processor--->process1stSection--->Process2ndSection--->Process2ndSection.....-->Return Response
------------------------------------------------------------------------------------------------------------------------------
TO
===========================================================================
REQUEST---->Add to DATA QUEUE
DataQueue-->Processor --->Add each section to respective queues.
Section1Queue---->Process section1
Section2Queue---->Process section2
:
SectionNQueue---->Process sectionN
=============================================================================
So, In place of handling the request from n threads(n requests running in parallel for these n requests), it will be handled by (N(number of subprocess) + 2) threads if no further optimization required. There can be case where we have say 3rd process section takes long time, so we can have 3 threads working to process 3rd section so only 2 threads increased and could process the request in faster and elegant way without putting too much load on system.
For in memory queue handling you can use framework as defined at here.