How does flow control and backpressure work for gRPC streaming, and why does it matter?
Last updated
gRPC inherits HTTP/2 flow control: per-stream and per-connection windows cap unacknowledged bytes, so a slow receiver throttles the sender (backpressure).
In callback APIs, check
isReady()/onReadybefore writing, or messages buffer unboundedly. Blocking APIs simply block the write until space frees.It matters because a fast producer with a slow consumer would otherwise cause out-of-memory errors or huge latency.
- https://grpc.io/docs/guides/flow-control/
- https://learn.microsoft.com/en-us/aspnet/core/grpc/performance?view=aspnetcore-10.0
- https://arpitbhayani.me/blogs/grpc-http2/
- https://builddistributedsystem.com/tracks/performance/tasks/task-31-1-5-http2-flow-control
- https://prachub.com/resources/grpc-streaming-debugging-interview-reproduce-backpressure-cancellation-and-stalled-reads
- https://github.com/grpc/grpc-java/issues/12853