One project, reservation system, core two tables: reservation table, reservation quota table

When the user clicks the reservation button,

1. Select the reservation quota table to retrieve the quota of the reservation period.

2. Select the appointment table to calculate the number of times the appointment has been made

3. Subtract the second step from the first step to get whether you can still make an appointment. If the value is greater than 0, you can make an appointment

4. Insert the reservation table if it is greater than 0 in step 3

The previous code was executed with ado.net+ SQL statement, and then in the formal operation, the appointment can be made at 18 o ‘clock every day, and then I set a certain period of time to make an appointment.

As a result, N people clicked the reservation at 18:00, which caused another person to calculate the reservation number again before inserting the reservation number, resulting in the exceeded limit

Asked a netizen, gave three solutions:

1. redis

2. Lock in c#

3. ConcurrentQueue in c#


Tested it on my own, used the second one, and it worked,


The third kind of words netizen also gave an example: