Let's say I have 2 functions add and subtract on the server. Can I use bidirectional stream in this scenario to increase throughput? If so, do I have to have an identifier for each request and response to distinguish between the responses(like reqId) at the client? Normally, they will be unary calls but want to increase throughput by streaming.
It is true that streaming messages have lower overhead than unary RPCs. Although the gRPC team tends to discourage using streams just for this performance gain unless it is actually necessary, as the messages can't be distributed onto multiple backends, multiple threads on one backend, and it is more complicated and harder to debug. Although if you are considering doing batching with unary RPCs, then streaming do have advantages you may prefer.
If the server computes responses in the order the requests were received, then you don't need a reqId; the 1st response would be for the 1st request, 2nd for 2nd, 3rd for 3rd, etc. gRPC streams preserve message order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With