What is HTTP/2 Server Push and gRPC streaming, versus WebSocket?

Topic: microservices, Real-Time Communication. Level: Hard.

Answer

- **HTTP/2 server push** lets a server proactively send resources it knows the client will need (mostly for assets; largely deprecated in browsers). It is *not* a general real-time messaging channel. - **gRPC streaming** (over HTTP/2) offers server-streaming, client-streaming, and bidirectional streaming with typed messages — great for service-to-service real-time and mobile, but limited in browsers without gRPC-Web. - **WebSocket** is the browser-native choice for arbitrary bidirectional app messaging. Use gRPC streaming internally between services; WebSocket/SSE at the browser edge. ```protobuf // gRPC bidirectional streaming — typed, multiplexed over HTTP/2 service Chat { rpc Connect (stream ClientMsg) returns (stream ServerMsg); // both directions stream } ``` ```java // Server-streaming example StreamObserver<ServerMsg> obs = ...; prices.forEach(p -> obs.onNext(ServerMsg.newBuilder().setPrice(p).build())); obs.onCompleted(); ```