I'm trying to build an appointment system but at one point I stuck


I define available slots for the next 7 days with help of a cron. I have multiple users serve service more than one location.

Now for example if - P1 location have two User U1 and U2 - P2 location has the only U1 user

now for P1 location, I can take 2 order for the same slot because two users are active on P1 location but if P2 request to post order then I can take that too.

but in an ideal case, I can take only two orders for the same slot for all location because i have only two uses

can anyone give some idea how i can solve this problem so that i cant take more order then i serve


This is a fairly common problem with many applications that have multiple users. The simplest solution is to check that the appointment is available before inserting and return an error if its taken. You can maintain a lock at the database level between the check and insertion to ensure another request doesn't get inserted. After this point it's a matter of improving the user friendliness, you can add a temporary locking on appointments when one is selected, but before it's confirmed, so that users get denied at the earliest possible time in the reservation workflow instead of at the end. You can also write your application so that it will periodically poll your database to see if available slots have changed to help prevent stale information from showing options that don't exist anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.