cloud pub sub

Can anyone tell following logic is possible or not:

I have one publisher and one subscriptions. I've sent 10 messages and want to ensure that each Subscriber receives 5 messages based on partitioning. Is there a way to achieve this in Google Cloud Pub/Sub? just like Kafka!

publisher (10 msg)  ------> (pull) subscription ---------> subscriber 1 (5 msg) and subscriber 2 (5 msg)

Solved Solved
6 2 93
1 ACCEPTED SOLUTION

Hi @Nikita_G ,

Currently, Pub/Sub does not support a built-in mechanism to ensure an exact 50/50 message distribution between two subscribers as you described. This is primarily because Pub/Sub does not use inherent partitions like Kafka, and it distributes messages based on subscriber availability and their pull rate. Additionally, it ensures at-least-once delivery, which means it targets one subscriber at a time rather than multiple simultaneously.

However, there are a few strategies you can consider to approximate this distribution:

Multiple Subscriptions with Filters: Create multiple subscriptions and use attribute-based filters to segregate messages. This doesn't guarantee an exact 50/50 split but can help with basic segregation.

Pub/Sub Lite: If you need partitioning and exactly-once delivery like Kafka, Pub/Sub Lite might be a good fit. It's cost-effective but has different performance characteristics than standard Pub/Sub.

Custom Load Balancing: Implement custom logic using Dataflow or Cloud Functions for precise control over message distribution. This is ideal for complex routing but adds complexity and maintenance overhead.

Choosing the Right Approach:

Consider your specific needs and the trade-offs of each option:

  • Strict 50/50 Distribution: Custom load balancing or Dataflow/Cloud Functions offer the most control.
  • Approximate Split with Simplicity: If an exact split isn't critical, start with multiple subscriptions and filters.
  • Cost Efficiency with Partitions: Pub/Sub Lite is a good choice if you value partition-based ordering and exactly-once delivery.

View solution in original post

2 REPLIES 2

Hi @Nikita_G ,

Currently, Pub/Sub does not support a built-in mechanism to ensure an exact 50/50 message distribution between two subscribers as you described. This is primarily because Pub/Sub does not use inherent partitions like Kafka, and it distributes messages based on subscriber availability and their pull rate. Additionally, it ensures at-least-once delivery, which means it targets one subscriber at a time rather than multiple simultaneously.

However, there are a few strategies you can consider to approximate this distribution:

Multiple Subscriptions with Filters: Create multiple subscriptions and use attribute-based filters to segregate messages. This doesn't guarantee an exact 50/50 split but can help with basic segregation.

Pub/Sub Lite: If you need partitioning and exactly-once delivery like Kafka, Pub/Sub Lite might be a good fit. It's cost-effective but has different performance characteristics than standard Pub/Sub.

Custom Load Balancing: Implement custom logic using Dataflow or Cloud Functions for precise control over message distribution. This is ideal for complex routing but adds complexity and maintenance overhead.

Choosing the Right Approach:

Consider your specific needs and the trade-offs of each option:

  • Strict 50/50 Distribution: Custom load balancing or Dataflow/Cloud Functions offer the most control.
  • Approximate Split with Simplicity: If an exact split isn't critical, start with multiple subscriptions and filters.
  • Cost Efficiency with Partitions: Pub/Sub Lite is a good choice if you value partition-based ordering and exactly-once delivery.

Okay, got it! Thank you.