user2107373
user2107373

Reputation: 437

Google Pub/Sub multiple topics v/s multiple subscription filters

I am working on a distributed highly scalable application using Google Pub/Sub as message broker. While going through the articles, I liked the subscription filter feature of pub/sub.

I was thinking of having a single topic with multiple subscriptions. Multiple publishers would publish discrete messages to the same topic. Each subscription would use attribute filter to pull messages specific to its requirement.

Does anyone know the drawback of using pub/sub subscription filters? Should I go ahead with this approach of single topic or create separate topics for each message type?

Upvotes: 4

Views: 4192

Answers (1)

Kamal Aboul-Hosn
Kamal Aboul-Hosn

Reputation: 17261

The choice between multiple subscriptions with filters or multiple topics comes down to a few things:

  1. Will any subscribers want messages from multiple publishers? If so, a single topic may make more sense so that your subscriber doesn't have to be aware of and create subscribers on many different subscriptions. There is also the question of how the subscriber would discover the set of subscriptions to which it needs to subscribe. Of course, you could use push instead of pull for this by pointing all subscriptions to the same endpoint, so that the subscriber does not need to be aware of the list of subscriptions.
  2. Are the messages from different publishers of the same type? If they are, a single topic makes sense. If, however, the types of messages are all different, then separate topics may make more sense. Otherwise, it's kind of like having a List<Object> in Java where every item is a different subclass.
  3. How much throughput? Even with filters, you still pay for the messages that are filtered out. Therefore, if you have 10 subscriptions on the same topic that each filter and take 1/10th of the messages, you still pay for 10 message deliveries. Of course, you don't pay for the actually processing power to do anything with these messages and you don't pay for any inter-region network costs, but you will still pay the $40/TB for messages filtered out. If you have a lot of subscriptions and a lot of messages, this could get expensive.

Upvotes: 9

Related Questions