Currently, I am utilizing Express.js for my project. There is an async function that performs a task that can take anywhere from 20 to 30 seconds to complete. Once the task is done, it increases a user's counter in the database. However, users are required to wait at least 24 hours before making another request.
The function first checks the last time the user's counter was updated before commencing the lengthy 30-second task. It only executes if the previous update occurred more than 24 hours ago.
But what happens if a user submits multiple requests almost simultaneously (let's say, five requests within the same second)? Will the function start the 30-second task five times and consequently increase the user's counter fivefold? This could potentially occur as all requests sent within the same second may not be recorded in the database during that time frame. Or will the function handle requests sequentially, processing one after the other, waiting for a response before moving on to the next one?
I aim for the API to manage asynchronous requests from the same user in a sequential manner.