Avatar
1
anaconda875 Beginner
anaconda875 Beginner
Sync to Async http request and response architecture
We are developing a REST service (2) that act as a adapter between a blackbox Client (1) and blackbox Processor microservices (4).

(2) and (4) communicate with each other using Kafka (3)

All components are stateless (except Kafka, right?)

First, Client initial a command to REST service using http POST (sync), then REST service take this command and forward it to Processor ms (after doing some conversion) via Kafka (async). After this step, REST service will sleep (this http scope) and wait the result from Processor ms

Then Processor ms handle this command and send the result back to REST service via Kafka (async). REST service wake up and and return the ResponseEntity to Client within same http scope.

Now we decide to migrate (2) to microservice to take advantage of this architecture. And the problem occurred: instance 1 of (2) send command to (4), and (4) send the result to instance 2. But the http session is established between (1) and instance 1, and instance 2 cannot return to (1). This returning must be done by and only by instance 1.

My first idea is, for example, let instance 1 be aware of the result from (4) no matter it was sent to which instance. But currently we have no solution to archive this idea.

This is the diagram

We need a "non work-around" solution for this architecture. Please help. Thank you

Note: we are unable to make change to blackbox components

  • Answer
architecture
Remain: 5
1 Answer
Avatar
tvd12 Beginner
tvd12 Beginner
The Best Answer
In this situation, you can give every message an ID, and then when a processor broadcast a response to the both instances of REST service, you can check the message ID and forward the response to the client.

But I think kafka is not suitable for RPC and for your situation. You can use gRPC, it's more suitable.

  • 1
  • Reply