Push Notifications with Firebase?

1,759 views
Skip to first unread message

David Katz

unread,
Oct 28, 2013, 4:29:04 AM10/28/13
to fireba...@googlegroups.com
Hi there. I have a question around push notifications. Hope someone has two minutes to read my use case. 

I’m building a group chat application in which every message carries some state (like, number of likes). Think of this like a public Whatsapp group for some topic, say, “Politics and the media”. I’d like to allow people to subscribe to push notifications for whatever room they’re interested in, and I’d also like to allow subscribing to notifications for messages that are “well liked”. This notification would only trigger if some number of likes threshold (say, 50 likes) is passed for the message.

Currently, the only implementation I have in mind for PNs with Firebase is a client side integration with a service like Urban Airship. In this scenario, when I post a new message to “politics & media”, I also hit the Urban Airship API with a request for sending out PNs to all subscribed users. This would probably work most of the time, but it’d certainly be less robust than an integrated solution. For example, what happens if I walk into an elevator between the successful write to Firebase and the attempt to hit the Urban Airship API? Or if the UA API is unavailable? 

These things I can probably deal with, but things start getting real hairy with my second use case — only sending PNs for messages with more than x likes. I can’t imagine how I would do that, since letting any client decide that they’re responsible for sending the PN seems prone to syncing issues. Any number of clients might hit ‘like’ at roughly the same time and locally think that they’re the ones who first crossed the threshold to 50 likes, which would get me duplicate notifications.

So that’s roughly my problem. Feature 1 seems doable but problematic, feature 2 seems not doable.

Bottom line I guess, it’d be great to get your thoughts on this.

Thanks for reading.

David

http://davidkatz.me

Michael Wulf

unread,
Oct 28, 2013, 12:33:15 PM10/28/13
to fireba...@googlegroups.com
David,

This sounds like a great use case for a queue worker. Instead of having the client responsible for notifications, which as you've noted is problematic, set up a node.js process to listen for queue events and perform the push events in a reliable manner.

We've also been experimenting with Zapier integration (currently experimental, alpha, invite-only). This would allow you to skip the node.js process since Zapier could pull out the queued entries and notify UA automagically. If you'd like to try out Zapier, shoot me an email off-list (wu...@firebase.com) and I'll get you an invite.

Cheers,
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-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

David Katz

unread,
Oct 30, 2013, 2:20:36 AM10/30/13
to fireba...@googlegroups.com
Thanks for the answer. Using a queue, who decided when to add things to the queue? As far as I can tell, clients can't decide for the same reasons they can't send out PNs. Or am I not getting something here?
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

Michael Wulf

unread,
Oct 30, 2013, 10:34:36 AM10/30/13
to fireba...@googlegroups.com
Hi David,

A queue is simply a pattern for dealing with volume operations in a reliable and throttle-able manner.

The overall process might look something like this:
  1. Use a transaction to increment your likes, when the counter reaches 50, have client queue a notification: https://gist.github.com/katowulf/c404bb4103c4dee636ee
  2. The notification is received by a server script for processing (or a service like Zapier)
  3. When UA returns a success code, delete the item from the queue in the server script
Security rules can enforce that the counter is only incremented 1 point at a time and, with a bit of creativity, to ensure the notification is only ever delivered once (by writing the record id to a secured path upon notification and checking that in security rules before allowing a write op into the queue)

Cheers,


To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages