What is the best practise concerning topic names
Asked Answered
B

2

20

What is the best practise concerning the topic name using google-pubsub.

If I have theses events :

  • customer email updated
  • customer address updated
  • customer created
  • customer deleted
  • article created
  • article deleted ...

What is the best practise concerning topic names :

  • create a customer topic and an article topic containing each one the events of its domain
  • create a deleted topic that will contains customer deleted and article deleted, etc ..
  • create a topic by event customer:created, customer:deleted, etc ...

Or an other ..

Boehm answered 11/4, 2019 at 16:5 Comment(0)
M
8

The decision one would make on topics really depends on the use case. If your entire system architecture has a clear delineation across customer/article or across created/updated/deleted, then it could make sense to split the topics along those same lines. If not, then there may be less use in splitting into multiple topics.

One way to determine how to do the split could be to consider the type of each message. If you split across all these topics, would they all have the same type of message (maybe an "event" message) or are the message types going to be different? If they are different, then different topics may make sense.

Most interesting might be the behavior on the subscribe side. Will the same subscriber be interested in events for both customers and articles or are their different subscribers for each? What about create/delete/update? A split along these lines sounds less likely. If all subscribers are going to be interested in all messages, then a single topic is probably reasonable. Otherwise, a subscriber will have to receive messages from multiple subscriptions. If some subscribers are interested in a subset of messages, then separate topics (and therefore, separate subscriptions) could be beneficial. Otherwise, the subscribers will have to look at all messages and immediately ack the messages they are not interested in, since Google Cloud Pub/Sub does not support filtering at this time. If it is a mix, then it is a tradeoff between more complexity in the subscriber interested in all messages (using different topics) and complexity in the subscriber interested in a subset (using the same topic and having to filter).

Madness answered 11/4, 2019 at 16:26 Comment(0)
I
0

I recommend your first suggestion; a customer topic and an article topic containing their respective events.

I like to group topics as I would a REST API for general things, and if there are specific business cases or special events outside of normal rest to have separate topics for those.

Going extremely granular with the topics to be one topic per event is a bit overkill in my opinion. Kamal Aboul-Hasn 's answer brought up the concept of filtering; as of today, there is now filtering options via the attributes of the message. See: https://cloud.google.com/pubsub/docs/subscription-message-filter

This allows you to make the subscribers handle granularity when required to split the various events.

Small downside is that a topic can only have one schema, so if your events significantly differ you won't really be able to rely on PubSub validating them for you.

Ideomotor answered 19/6, 2023 at 3:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.