G
G
goodlike_by2021-02-07 13:13:15
Laravel
goodlike_by, 2021-02-07 13:13:15

How to optimize API requests?

Hello! Essence of a question:

There is an API on Laravel.

There is a react application, the essence of which is to collect from the chat in a given period of time (for example, 1 minute) the correct answers of users and throw them through the API into the database and after the specified time, count the number of correct answers and distribute points. But since there are a lot of requests to the database, it turns out mini ddos ​​and the server either blocks calls to the database, or the requests are stacked and, for example, 10 responses come from 1 person and 0 from the second.

Accordingly, the question arose of how to optimize this whole thing. Am I digging correctly towards asynchronous requests in React and the request queue and jobs in Laravel? Or something else to see?

I would be very grateful for the help

of UDP by numbers:

1. Time to collect answers 30 seconds or a minute
2. Users from 3000 to 5000
3. Delay between answers for users 5 seconds
4. A group of users (about 100 people) who do not have a delay between answers and can give an average of about 10 answers per give me a sec

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Adamos, 2021-02-07
@goodlike_by

If points are counted only at the end, why write each answer? We collect them at the front and send them in a bundle at the end.
Does a database validation request include a user response? It is more logical to take the correct answers from the database (the request is cached and will not pull the database) and compare them with the user's answers in the script, accessing the database only to write the answers and the result - once.

D
Developer, 2021-02-07
@samodum

Use RabbitMQ for the queue and Redis as the database.
Or do sharding if you have a relational database like MSSQL, MySql or PostgreSql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question