Queue users in a web (MERN) application?

Viewed 82

I am trying to make an online teacher-doubt solving MERN application.

The workflow is as follows:

  1. A user of the app clicks on the "Ask Doubt" button associated with the teacher.

  2. The user makes the payment.

  3. The user is then added to the queue where he/she waits for the doubts of the people ahead of of him/her to be resolved by that teacher. (Edit: The user and the teacher go into a chat room then and the others will wait in the queue)

I also want to display the number of people in the queue already in the queue so that the user can only pay if they have enough time.

I cannot guarantee the average time for each doubt session so I cannot ask the user to come in after some x amount of time.

Also, feel free to suggest some other implementation if u feel my approach isn't good.

2 Answers

Edit: Since you dont have a Doubt Model, you could create a queue model. Which consist of an Array with the user ids.

Then you can do queue.array.length to get the amount of people in the queue. And when they are in the chatroom or finished. You update the array by removing the user from the array.

Although there might be other ways to solve the problem too, I think using Cassandra as your database might be one of the solutions for you.

You can design the use the teacher id (or name) as your Partition Key and use the timestamp as your clustering column.

When you want to get the details of the person who is next in the queue, u can simply query the first student under that partition (teacher id).

When you are done asking, you can delete then delete the first row.

As I said before, there might be other ways, but this is certainly one of the simpler solutions if scalability is what you want.

Related