M
M
MMelnikov2021-11-18 12:07:11
PHP
MMelnikov, 2021-11-18 12:07:11

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:

  • backend in PHP
  • MySQL
  • all incoming messages must be saved
  • microservice for processing can "fall"


For understanding: this is a chat with the server. The client asks a question, a separate microservice finds the answer and returns it. To reduce the load, it was decided to send requests in batches (of N) pieces. The client waits for a response from the server T time, if there is no response, then another algorithm is executed on the client.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2021-11-18
@Stalker_RED

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 question

Ask a Question

731 491 924 answers to any question