-
First Check
Commit to Help
Example Codeuvicorn main:app --workers 4DescriptionIf you have some sort web service that has multiple functionalities and one of which allows booking a limited resource. But you want to using multiple uvicorn workers to enable smooth performance, how can you ensure that there are no duplicate bookings/booking the same slot since they can happen in theory at the same time Operating SystemmacOS Operating System DetailsNo response FastAPI Version0.87.0 Python Version3.9.6 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
There are many ways. Usually things like this are handled in the database using things like transactions (and other functionalities, sometimes it depends on the database in use) . If a database can offer these guarantees it is usually said to be ACID compliant. Each worker will attempt to make a booking in the database, but only one will succeed while the others will receive an error. There are many other algorithms for distributed locking but they can be considerably more complicated you wont need them for your particular example. |
Beta Was this translation helpful? Give feedback.
There are many ways.
Usually things like this are handled in the database using things like transactions (and other functionalities, sometimes it depends on the database in use) . If a database can offer these guarantees it is usually said to be ACID compliant.
Each worker will attempt to make a booking in the database, but only one will succeed while the others will receive an error.
There are many other algorithms for distributed locking but they can be considerably more complicated you wont need them for your particular example.