169 похожих чатов

So in a movie ticket booking scenario If user A

and User B tried to book a slot at 3pm at the same time
My backend will receive the req and it will check whether that seat is available or not in my database
So two request will be sent to db from my server for the user A and B, it will return that seat is available for both users
So server will try to book for both
I am using nodejs as backend so the db op will be async

So how do I prevent this thing ?
Should I use some global variable or something and lock a particular seat so after db operation if the variable is not locked that user can book and the variable will be locked so when other user tries to access that variable it will say the slot is already chosen

3 ответов

7 просмотров

How is it stored? Are the "seats" already there(as unbooked) and are they updated as someone books them or are the table rows inserted as the person books them?

Use queueing system, where you process requests one at a time. There are many such libraries Or have a pool of available seats in memory and remove when claimed

Richard | Dm for Paid Support
Use queueing system, where you process requests on...

When you say in memory what kind of databases are we talking about here? Redis?

Похожие вопросы

Обсуждают сегодня

Anyone here suffers from unexplained aural migraines, who would be up for talking for a bit? Doesn't *have* to be aural, but I am not asking about headaches, I mean actual mi...
Martin Rys
55
Я тут за тем, чтобы задать вопрос, так как не знаю ассемблер, учу с/с++. Короче, насколько дорога операция перехода в функцию при ее вызове? Дело в том, что в с++ есть макросы...
Максим Рябцев
12
А какие чаты вообще в ходу? Auto aim? И что еше
do you think you're better off alone? А
13
Привет, нужен совет старших товарищей. Есть глобальная переменная var DefaultDataFolder:string; инициализируем DefaultDataFolder:='a:\_OUT\'; есть примитивная процедур...
Max Otto
14
hello friends. Do you know how can I learn getx? I have a software project that I should deliver it up to 5 weeks later and I need to learn firebase too. I will be thankfull
AmirHossein Razavi
15
Доброе время суток! у меня тут иноды закончились. и понял почему по сути кстит, я периодически очищаю постгрес и сентри контайнер: postgres=# DELETE FROM nodestore_node WHER...
Юсиф Насиров
9
Вопрос. Теоретический. Есть список команд. Команды отправляю в обработку некой функции, по очереди. Разные команды могут давать разные результаты после обработки. В зависимос...
Serjone
7
lazarus-3.2.0/gtk, linux патч "имя проекта по умолчанию project1 -> prj" день добрый не нравится "именя проекта по умолчанию" (project1), к.раз приходится переименовывать (н...
livontiy
5
Коллеги, а в чём сейчас хорошо писать на перле, в смысле ide? Пробовал в идее с плагином, подсветка есть, даже какие-то предупреждения есть, но рефакторинга считай нет. Перене...
Дмитрий Петров
9
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
Карта сайта