Multiple Topics Versus SingleTopic in Google PubSub

Viewed 2569

While designing an event delivery system with 10 different event types,I see two options to model topics on Google PubSub. Either each of the event type can be queued in a different topic or all the 10 events can be queued in the same topic. Each of the events will have different subscribers and it's possible to queue the events in the same topic but filter messages on the subscriber side. I am looking for a very high throughput with minimal latency, should I go for a single topic or multiple topics?

1 Answers

Filtering on the subscriber side isn't a good idea: you will use more resource (and cost more money) and you will inject latency (if the message is received by the wrong subscriber, it is rejected,...)

So, there is 2 solutions:

  • Create as many topics as you have type of event. But it's at the publisher to perform the filter and to publish in the correct topic. In addition, if you have new event types, you need to create a new topic and condition to deliver in it. Not ideal
  • Create only one topic and to filter at the subscriptions level (not the subscribers level as proposed in your question). For this, you need to add the event type as PubSub message attribute and then you can create the subscriptions that you want on the correct attribute filtering rule. The publishers don't know how the message are consumed and in case of new event type, simply create a new subscription with the correct filter.
Related