I have X micro-services each of them are them are publishing to the same pub/sub topic. The messages they publish contain the micro-service ID.
I am looking for a way to make sure that the pub/sub has finished servicing all the messages of a certain micro-service.
My current solution is to count all the messages that were published from the micro-service, and then count the messages that were served in the pub/sub topic (via cloud-function). There are some known issues with this approach, and I was wondering if there is a better way to know if the pub/sub does not contain messages from the specific micro-service?
The solution I ended up with is as follows:

create a set in redis, and add a new message id to it
Include this new message id in the message published to the pubsub
the cloud function that runs after the pubsub should remove the new message_id from the set
by the end of the process, we check the set and if it is empty then the process is done.

This also handle the times when pub/sub publish the same message more than once.
How to know if the pub/sub topic contains messages with specific content?