I have a microservices architecture for an app. I have a service S1 that can fetch data and store it somewhere. Then 2 services, S2 and S3, both running very different ML tasks. When S2 or S3 need data, they publish a message to the PubSub on a topic called fetch_request. The service that fetches data continiously pulls from this topic, fetches the data. When it finishes a task, it publishes a message on a topic called "fetch_done" to let the service that made the request know that the data has been fetched.
My question is: how to make sure S2 and S3 don't consume messages from "fetch_done" that they were not supposed to consume ? I thought about solutions but I'm not sure:
may be when trying to pull from "fetch_done" I could add a filter to only pull message if they contain a UUID that I would have written in the initial request message ? This way, you can only pull a message if you know the ID. Of course the service that fetches data will then need to put the id in the response.
Kinda the same idea, but may be just add the name of the requesting service in the initial request instead of an id ? The problem with this one is that eventually, a service could impersonate another service if I'm correct, and as I probably won't be the sole developer of every service in the app, I think the UUID is a better idea.
Something obvious I completely missed ?
There is several patterns that you can implement. IMO it's better to have 1 subscription per service. Like that, the S1 post a message in a topic and the message is duplicated in each subscription.
Now, you can:
In any case, because the communication is async you need a element to distinguish the correct receiver of the messages. The 2nd solution, with the pubsub filter is the most efficient (I think).