Implementing Firebase Queue for multiple Users

59 views
Skip to first unread message

himanshu kapoor

unread,
Apr 23, 2017, 10:41:49 AM4/23/17
to Firebase Google Group
I need to implement queues, to avoid duplicate invocation of the same request due to firebase sockets running on multiple instances.
I know how to use queues, it's just I need some help that where should I write/add task in queue it

I have multi-user App, all users have their nodes in firebase and each user can only access their child nodes data.

Where to add a task in queues? like if I am adding a task in queues inside child_added listener and two instances are working on the cloud means listener trigger 2 times and 2 task will be added in queues, How can it be solved?

DB structure looks like this:

App/
- UID1
  - websiteURL : example.com
    analytics:
  visits: 87687
      productPageVisits : 13070
      gender: M
  timeStamp : 1490293800000
  
- UID2
  - websiteURL : example2.com
    analytics:
  visits: 20020
      productPageVisits : 130120
  timeStamp : 1490293800000

UID1 is unique id of user 1 and can only access nodes below after authentication, same is UID2

Node Js code:

 ref.child('app').on('child_added', function(root) {
 
 // dynamically get UID from root and map listeners
var UID = root.key();
 ref.child('app').child(UID).on('child_added', function() {
 
   // bind child nodes with event listeners
   
 ref.child('app').child(UID).child('analytics').on('child_added', function(snap) {   
 
   // and so on bind other child nodes with all UIDs
    
   // get previous visit count using once, increment with 1 and update
// Currently :add task in analytics queue
 
 })
 ))

and how many workers should I provide to handle around 200K concurrent users(each user has their own users like UID1 website users)? and should create 1 big queue and inside it starting other small queues? or else

Kato Richardson

unread,
Apr 24, 2017, 1:23:03 PM4/24/17
to Firebase Google Group
Hello Himanshu,

Check out firebase-queue. It solves this by using transactions to "claim" the queued events, so multiple workers can process items in parallel. Alternately, you can use Functions, which would trigger a worker for each add event.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/01cf17c3-f244-445d-8736-0f769575d0b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages