Search code examples
microservicessagaevent-driven

How can I response status code with asynchronous Request/Response?


Hello I'm trying to make a toy project and made SignUp API with Saga Orchestrator and kafka.
And I need to respond JWT Token when success to client.
When I create user in PENDING state, I need to respond to request and send kafka message to other service.
When other service success, user service update their state to CREATED.
But I don't know how to respond http status code and response body to client.
How can I send response to client?

Follow is my flow chart enter image description here


Solution

  • In cases where your request is being processed in Async manner (like Kafka, RabbitMQ etc), an ideal solution would be to use HTTP 200 Accepted or HTTP 204 No Content response.

    These status code indicates that your request was valid and has been taken up, however, you don't certainly need to send a response body in return !

    At the most, it would be sufficient if you'd return a response with a JSON or XML or text message saying something like this ...

    Http 200/204
    
    {
    
    "success": "your request is processing..."
    
    }

    You may read about response codes here https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200