0

I'm currently developping an appointment system using Java (spring boot) and I'm facing an issue,

When two (2) users ask for the same timing almost simultaneously my verification does not work

Explanation:

New request recieved

// Fetch all the previous request from the database and checks if there is any kind of conflicts
Verification();

// If no conflict found 
saveAppointment();

Example:

User1 ask for appointment at 11:03:50 Date: 12/12/2020 Starting: 10:00 Ending: 12:00

User1 ask for appointment at 11:03:51 Date: 12/12/2020 Starting: 10:00 Ending: 12:00

Problem: The system saves both without finding any issue because both happen at the same time and the system is not able to fetch any previous appointment.

Is there a way to make the system wait when there is a request going on and only take another one when the first is done ?

1 Answers1

0

I think you should consider using some kind of locking inside your application or your data storage. Classical approaches for SQL data storages (but also can be used with NoSQL) is Optimistic or Pessimistic Locking. You can check a brief explanation of these approaches here.

Here you can find the example of optimistic locking realization with Spring Boot and JPA, and here - the example for pessimistic locking.

Sergey Vasnev
  • 783
  • 5
  • 18