'Prevent Laravel Web-App / Webserver from getting overloaded

I have the following challenge... I created an appointment booking system with laravel 8, which allows people to book appointments which are then available in the admin area for the employees.

The webapp itself is running for a couple of months, but now I am getting more and more users, which lead already a couple of times to the situation, that the webserver / mysql was so overloaded that the website was not loading any more.

Analysis has shown, the too many queries are executed, as the calculation for open available time slots query the bookings table in the db, which got quite big over time (1.7gb table).

Surely I can optimize the db queries etc. but I still afraid, that too many concurrent web requests may lead to db/webserver blockage.

My question now is, what options would see to prevent this situation?

Apparently the main cause is the checkin of the available time slots function, which is executed every time the user selects a date in the dropdown (it will then execute an ajax call, which fetches the available time slots).

I was thinking about two possible solutions:

  1. Queueing: would it make sense, to execute this ajax call as a Queued Job, so that not too many requests can block the db?

  2. replace the ajax call for getting the timeslot with an internal api request? Hence instead of directly asking the db, I would as my backend API to get the time slots, which then may throttle the requests if there are too many?

  3. Or are there better options???

I hope you could explain the issue and my desired target.

Thank you very much in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source