I have a server which is constantly getting a lot of requests every second. Some of them have similar parameter e.g. userId.
At this time I'm processing every request separatly (let's call an action for each request as A).
I would like that some worker perform only one action A for all requests with the same userId.
Example:
Unix time 100
My server receives 10 requests with userId = 1 and userId = 2, returns status Ok and passes requests to the worker which groups the requests by userId and produces the action A, first with data userId = 1, then userId = 2 (order is not important).
So there are only 2 actions A instead of 15.
Then worker takes requests with unix time 101 groups them and performs action A ...
It is necessary that the time delay and resource costs are minimal.
I'm confused. How can I implement this?