# Slot Booking Capacity Management

**URL:** <https://forum.djangoproject.com/t/slot-booking-capacity-management/17716>\
**Category:** Using the ORM\
**Created:** [December 19, 2022, 11:21am UTC](https://forum.djangoproject.com/t/slot-booking-capacity-management/17716 "2022-12-19T11:21:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yeole-rohan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/yeole-rohan/32/8173_2.png) [@yeole-rohan](https://forum.djangoproject.com/u/yeole-rohan)\
**Post date:** [December 19, 2022, 11:21am UTC](https://forum.djangoproject.com/t/slot-booking-capacity-management/17716/1 "2022-12-19T11:21:05Z")

</div>

In booking system, I have slot with capacity. now lets consider there is only 1 capacity is available and more two users are trying book the slot, at the same time. how I can handle this scenario?

looking for any solutions from community.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 19, 2022, 12:47pm UTC](https://forum.djangoproject.com/t/slot-booking-capacity-management/17716/2 "2022-12-19T12:47:33Z")

</div>

How do you want to handle this scenario?

In general, there are a couple different ways to handle it, but you’d probably want to lock the table whenever the form is submitted to book a slot, to ensure that there are no race conditions with other submissions.

The specifics are really doing to depend upon your data model and your views.

---

<div class="post-metadata">

**Author:** ![yeole-rohan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/yeole-rohan/32/8173_2.png) [@yeole-rohan](https://forum.djangoproject.com/u/yeole-rohan)\
**Post date:** [December 19, 2022, 1:20pm UTC](https://forum.djangoproject.com/t/slot-booking-capacity-management/17716/3 "2022-12-19T13:20:04Z")

</div>

You are right, Would like know more about locking the table row instead of table as there will be parallel booking might be happening on different rows.

or

can it possible like first in first out ?  
if yes, what supporting packages will be needing for this.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 19, 2022, 1:42pm UTC](https://forum.djangoproject.com/t/slot-booking-capacity-management/17716/4 "2022-12-19T13:42:13Z")

</div>

> [@yeole-rohan](#):
>
> Would like know more about locking the table row instead of table

See [`select_for_update`](https://docs.djangoproject.com/en/4.1/ref/models/querysets/#select-for-update)

> [@yeole-rohan](#):
>
> can it possible like first in first out ?

Yes, but is that really appropriate from a UI/UX perspective?

To implement this, the process would need to be independent of your Django processes, perhaps using something like a Celery task queue or a Channels worker, or a bit of code in your Django app to manage your own semaphores. (I really don’t recommend that last one except under some unusual circumstances, but it _can_ be done that way.)

---

<div class="post-metadata">

**Author:** ![yeole-rohan](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/yeole-rohan/32/8173_2.png) [@yeole-rohan](https://forum.djangoproject.com/u/yeole-rohan)\
**Post date:** [December 19, 2022, 1:49pm UTC](https://forum.djangoproject.com/t/slot-booking-capacity-management/17716/5 "2022-12-19T13:49:19Z")

</div>

Will try by select\_for\_update first, seems easy solution. if not then with other options. @KenWhitesell thanks for this advice and congratulations on your work anniversary by the way. 🤩 🤩 🤩
