Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Acknowledgement Behaviour of GCP Pub/sub messages

i’m working on micro-service that contains subscriptions to a topic in GCP Pub/Sub. As multiple instances of a Microservices run on more than one host (multiple clusters on cloud), I wanted to know acknowledging behaviour of messages from subscribers. When a subscriber on one instance receives, process and acknowledges the message, does the same subscriber on other hosts receive the message or not?

I expect that once the subscriber acknowledges, pub/sub doesn’t further send the message, but what if two same subscribers on different hosts receives message at the same time, does it cause duplication?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Pub/Sub delivers each published message at least once for every subscription.

https://cloud.google.com/pubsub/docs/subscriber#at-least-once-delivery

If you want multiple "workers" to not receive message clones, you need to use a single subscription for all of them.

This is because for events you can have multiple systems listening on the same topic, on different subscriptions so that all the systems receive the event that something has happened.

For commands, you usually want a single system to handle them (even if split between multiple workers) so you would need a single subscription that is shared among all the workers.

By the way, your system should be idempotent in processing events/commands from a topic. The general rule of thumb is that each message is guaranteed to be received by a subscriber at least one time. Meaning the same system could potentially receive the same command two times.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading