I'm designing a system that uses a microservices architecture with event-based communication (using Google Cloud Pub/Sub).
Each of the services is listening and publishing messages so between the services everything is excellent.
On top of that, I want to provide a REST API that users can use without breaking the event-based approach. However, if I have an endpoint that triggers event X, how will I send the response to the user? Does it make sense to create a subscriber for a "ProcessXComplete" event and than return 200 OK?
For example:
I have the following microservices:
- Service A
- Service B
- Frontend Service - REST Endpoints
I'm want to send this request "POST /posts" - this request sent to the frontend service. The frontend service should trigger "NewPostEvent." Both Service A and Service B will listen to this event and do something.
So far, so good, but here is where things are starting to get messy for me. Now I want to return the user that made the request a valid response that the operation completed. How can I know that all services finished their tasks, and how to create the handler to return this response?
Does it even make sense to go this way or is there a better design to implement both event-based communications between services and providing a REST API