Spring / Spring gRPC Interview Questions
How does backpressure work in gRPC streaming, and how would you handle a slow consumer?
gRPC relies on HTTP/2's built-in flow control, but on the server side you can also cooperate with it explicitly using a ServerCallStreamObserver. Before writing each message you can check isReady(); if the client hasn't caught up yet, you hold off on further onNext() calls rather than buffering unboundedly.
You can also register a callback via setOnReadyHandler(), which fires once the observer is ready to accept more data, letting you resume sending exactly when capacity frees up. This prevents a fast producer from overwhelming memory when paired with a slow consumer, which is the streaming equivalent of what reactive backpressure operators do for reactive streams.
More Related questions...