CharstarAdmin
CCConvex Community
•Created by CharstarAdmin on 9/21/2023 in #support-community
Implementing a virtual waiting room
I'm looking to implement a virtual waiting room to gate access to my product (I estimate I'll have roughly 2000+ users waiting concurrently). Users (each has a unique Clerk user ID) should see their position in the queue and then eventually be added in FIFO order to the main room when there is space (room has a fixed capacity). They'll get booted from the main room back to the queue if they are inactive for 5 minutes.
I was thinking I could use a mutation to add users when they open the website and use the ‘by_creation’ index but not sure how to 1) efficiently query their position in line and 2) boot inactive users (e.g. if they leave the site).
Perhaps I could have each client "listen" to the front of the queue (i.e.
order('asc').first()
) and respond accordingly if their ID matches it. If I have a global counter, I can add a field to the schema that stores the counter value at time of insertion with each user in the queue. Then, the difference between the user's value and the front of the queue's value is the user's position in line.
Not sure how to drop users from the queue if they leave the site. Maybe I keep a heartbeat timestamp for each user in the queue? I noticed there was some discussion about sendBeacon and presence earlier.
Anyways, do you think Convex is the right tool for this use case? Do you have a simpler proposal?
I'm using Vercel/NextJS with API routes + Planetscale + Clerk right now. I will also need Expo/RN support.114 replies