0

I am building an application that is using most all of the firesbase products and im not sure how to tackle a specific problem with a queue.

What im needing to complete is a system to allow users to purchase tickets but before they are paid for they are in the users 'cart' for a specific period of time, lets say 5 minutes. This is similar to how ticketmaster or other companies do it.

firestore layout:

root
--accounts
--tickets? <-- not sure on this
  --abc123
    --description: 'Dinner with the Chef'
    --tickets
      --sadf76s8d7fsd
        --ticketDesc: 'Ticket for 1 person'
        --available: 1000
      --sd78fsd8788f8
        --ticketDesc: 'Ticket for 1 person plus Guest'
        --available: 50
  --lmnop555
    --description: 'Tuesday Dinner Event'
    --tickets
      --8gh98f8959f8dgf
        --ticketDesc: '1/2 price dinner'
        --available: 500
--Dinnersales
  --asdf4jn23kj4
   --description: 'Have dinner with your favorite chef!'
   --tickets
     --['sadf76s8d7fsd', 'sd78fsd8788f8']
--users
--other-data

What i not sure how to implement properly is the queue system. I was thinking that once the user tries to put those tickets in their cart, i would first check to make sure there are available tickets, if there are then pull those tickets out of the total available. If the user completes the transaction before the 5 minute timeout period then all is good. If they dont complete the transaction before the timeout then put those tickets back in the pool of available tickets to the public.

It seems that maybe this is not the best approach for this type of issue? Maybe it is? Im wondering if im going about this the wrong way, any suggestions would help.

user616
  • 783
  • 4
  • 18
  • 44
  • That's probably not the best sequence and hopefully you will be using an external [Cron job with Firebase](https://stackoverflow.com/questions/42790735/cloud-functions-for-firebase-trigger-on-time) to handle the timeout. I would suggest each ticket have a child *status* node an a *sold_to* node. Status would be available, on-hold and sold, and the user it's holding for or sold to would be the users uid. – Jay Sep 04 '19 at 18:13
  • @Jay Yes the timeout would happen on the backend somehow. UI would just have a timer to give the user a countdown to show how much time is left. – user616 Sep 05 '19 at 00:51
  • I just created an open-source package to create a queue system using Firestore and Firebase Cloud Functions. [Check it out](https://github.com/sbarbat/firestore-queuer) – Santi Barbat Aug 12 '20 at 17:25

0 Answers0