Friday, August 26, 2016

Efficiency by grouping requests and events

In general programming world, every request gets a response, which is how it is supposed to be. But what if similar requests are received at the same time. The solution is

  1. The program has to process every request individually and provide the response.
  2. We have the cache the response for the first request and return the same response for the similar request which is repeated.

The problem with the first one is the duplicate effort which could have been avoided. The problem with 2nd solution is that we assume that the caching layer is available and both the requests are exactly same (no difference in context).

What if the program or the internal engine which runs the program like (JVM or V8 engine) is able to handle such similar requests, group them together, process the request and respond to all of them at once.
This logic can be event based in event driven languages like Nodejs or even at method/function level.

Nodejs:
Nodejs is a event driven programming, where every request goes into the event queue. If the engine is able to sub group the events and process similar events in one go, it would mean using less resources to process same amount of events.

Need some thought on how this can be achieved.