Answer the question
In order to leave comments, you need to log in
How to ensure read consistency?
Hello! Interested in solving the issue in the API service with a stack:
- NodeJS 10
- MongoDb 4.00
- Mongoose ODM
The essence is this: the hotel reservation service provides room availability. But if in 1 second or less 2 users book the last place, then the reservation will work for two at once, since the first request for access to the reservation will work faster than the second one, which will subtract and save. For example:
Two people apply for 1st place and at the same second they both apply at the same time. Both read the available places and both have the last place available. But for the first one, the reservation works earlier and the place is updated, (read = 1-1) - you will write down 0 (not available) for the second one in the same way. It turns out both booked 1 place.
I think you need to dig into Mongo to set up consistency. What do you think?
Answer the question
In order to leave comments, you need to log in
When writing a reservation in the selector, additionally check the condition so that the place is still available.
It is necessary to dig in the direction of ACID transactions, blocking of records and updates of records with conditions. (On the example of SQL: update table set free = 0 where id=1 and free =1 and updated =13677742126)
I seem to have learned in ACID in the latest releases
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question