Answer the question
In order to leave comments, you need to log in
Processing calls in batches?
Good afternoon, comrades!
Need help with system design. The bottom line is this: the server receives requests from various clients, as soon as N requests are accumulated, the requests are sent to the handler, then the response is sent to N clients. The client waits for a response from the server in T seconds. All this time (T) new packs are accumulated and sent to the handler.
What is the best way to implement this functionality?
Introductory:
Answer the question
In order to leave comments, you need to log in
There are such things as message brokers , they are specially designed to quickly receive messages from different sources, and transfer them to handlers or clients on demand.
There is a whole list of them at the link, of varying degrees of sophistication.
examples:
https://habr.com/ru/post/488654/ RabbitMQ
https://habr.com/ru/post/496182/ Apache Kafka
Which one is best for you is hard to say now.
You can also use Redis for this purpose.
In general, the scheme is something like this: You
accept all messages in a row, put them in the status "in queue".
The handler takes the message, puts the status "in progress" and the date.
If processed - changes the status to "processed".
Some watcher periodically checks those that are in work, and if a lot of time has passed, it changes the status "in work" to "in queue" and puts an error counter. If the Errors are repeated, it changes the status to "there is an error in the message, sort it out"
The story is similar with delivery to subscribers, only the status is not "in work" but "waiting to be sent", "sent", "accepted", etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question