Spring / Spring gRPC Interview Questions
How do you implement a bidirectional streaming RPC?
The service method itself returns a StreamObserver<RequestType> and also receives the response observer as a method parameter. Inside the returned observer's onNext, you handle each incoming client message, and you're free to call responseObserver.onNext(...) at any point - the two streams operate independently over the same logical call.
sequenceDiagram participant C as Client participant S as Server C->>S: request 1 S-->>C: response A C->>S: request 2 S-->>C: response B C->>S: request 3 (end of client stream) S-->>C: response C (end of server stream)
Both sides typically call their respective onCompleted() when done sending, and either side can terminate early with onError. This shape is what backs use cases like live chat, collaborative editing signals, or continuous telemetry exchange between services.
More Related questions...