Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Pendo's avatar
Level 10

High performance multiple date checks: how to?

Sorry for the long read, it's needed to make clear what I'm after and what I have already.

So, I've ran into this issue before but that was on a much smaller scale than what I am about to develop right now. A few years ago I did a small calendar app for a hairdresser. His business had a few hairdressers and each one of them had their own set of abilities (coloring, cutting, washing, etc.) The end user was able to select a service and/or a hairdresser with a desired date and was prompted with a list of available times.

I kind of need the same setup but on a larger scale. There will be multiple businesses, with each multiple hairdressers and multiple services. Also the (expected) amount of visitors that are going to use this app is much higher than before which got me thinking whether or not the method I'm using won't be too slow or asking too much from the server.

I'll try to sketch the way I did it before:

(1) The user selects a date and a service (the hairdresser is optional): the service determines the length of the appointment. Let's say it's 45 minutes.

(2) The script loops the available hairdressers for the given day. So if there where 3 available, the steps below are looped 3 times.

(3) The scripts searches for existing appointments between the start of the day (e.g. 8:30) and the maximum length of the appointment: 9:15 (8:30 + 45 minutes).

(4.1) If no appointment is found, the spot is available. Return to step 3 and check between 9:15 and 10:00

(4.2) If an appointment is found, the end of the latest appointment is taken and set as start for the next search. So if between 8:30 and 9:15 two appointments are found (8:30-9:00 and 9:00-9:45), the script repeats step 3 searching between 9:45 and 10:30 (again: 9:45 + 45 minutes).

This continues until all available times for a day for all hairdressers are found and presented to the user.

Is this the best way do to the availability checks? and what are my options to speed up the results. In an empty agenda this script would query about 16 times for a 30 minute appointment between 8:00 and 16:00 for each hairdresser. That would be 48 (unnecessary) queries.

I could perhaps select all available appointments for each hairdresser on the given date (3 instead of 48 queries) and than create a for-loop myself for the times and disable all times where an appointment is already set.

On the other hand, maybe using ElasticSearch will speed up the results as well (I'm planning on using ES anyway, but I'm not sure on what the performance difference would be).

Any help is greatly appreciated, I guess I need a little insight in how other people do this since I'm stuck on the vision above and I can't get myself to think outside the box right now.

0 likes
2 replies
Pendo's avatar
Level 10

Thanks @jlrdw, but the answers are to basic there. He's working with a default length of the appointment. I'm after a "length independent" solution without having to load the server too much. I think I kind of have answered my question myself yesterday while explaining myself (fetch all appointments and check free spots without using any extra query). But I'm open to discuss this with others if there is anyone willing to discuss this.

Please or to participate in this conversation.