Question

I've been playing around with Redis and Faye for a system I'm building. I'm still not sure if they are the best choice for my specific application.

My goal

Each user is able to publish a message to a channel/topic and to receive messages from the topics he subscribed to. Topics must have a hierarchical structure (i.e. topic "B" is a subtopic of topic "A", so we have a "A->B" relationship between the topics). If a user subscribes to a subtopic, he just receives messages from that topic (he subscribed to "B" in "A->B" and just receives messages in "B"). If a user subscribes to a master topic, he receives all the messages from the subtopics (he subscribed to "A" and receives messages for "B" and other subtopics of "A").

Users should receive notifications on their mobile using Push Notifications (Android/Apple).

What I tried to do

I tried to simulate the hierarchy by publishing messages to all the channels of the hierarchy. Let's say we have this hierarchy: "A->B->C" "A->B->D" so that B has two subtopics.

Publishing to C means, for a publisher, sending messages to channels "A", "B" and "C". Publishing to D means, for a publisher, sending messages to channels "A", "B" and "D".

Issues

Is there any better way to do this using Faye backed by Redis or just Redis? If that's the best approach, how does it scale with the increasing number of publishers/subscribers and topics? How to achieve the stream update through the mobile push API?

Was it helpful?

Solution

You should consider the PSUBSCRIBE command in redis.

With PSUBSCRIBE clients subscribes to a pattern instead of a single key.

You can easily encode the hierarchy in the key naming (say you have topics:A:B:C), when a client subscribes to topics:A:* it will receive messages published on topics:A:B and topics:A:B:C

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top