I’m trying to design a mobile application which allows registered users be added to a queue. request a number from a web service which then responds with a stored number. The next requesting user will get the consecutive number.
I’m using C# as Server side language and mySQL for the users database.
the Client side sends an HTTP POST request where “Authentication” header is “username:password”, “x-action” custom header is “joinQueue”. And gets his number in the queue. Later on he can poll the web servie with “checkQueueStatus” action to see where he is now in the queue.
The Server side the does the following:
- access users DB and check if username:password exist (are correct).
- send the last_number+1 and update an HTTP response body.
- store the info that, say, userID 123123 is 31 in queue.
- update the queue for all users once the first-in-queue is done being serviced.
As a noob to web-services I’m not quite sure about how to design the Server Side part.
Specifically, does it make sense to create a different table, a queue table, with the following info:
userID | placeInQueue
301452 1
444592 2
612712 3
042125 4
and an administrator-client can now send an HTTP request with a “serviceFirstUser” action which will decrease the placeInQueue for each and every person in queue?
Is that a plausible design?
Thanks.
Using the QueueTable is a good idea, but you don’t need to do it:
You could just index the placeInQueue and then get the max_place-min_place
So, you just get the place of the first user in the queue (in a constant complexity):
Then you can get the position of an user in a logarithmic complexity:
His real position is (his placeInQueue)-(placeInQueue of the first)+1.
Then you don’t need to do a linear update… removing the first could be done in logarithmic complexity (constant for the placeInQueue indexing + logarithmic for the userID one).