I want to develop a client-server application in a bi-directional streaming manner.
what is more suitable technology for this, grpc or websocket?
To be more precise, the direct comparison shall not be about WebSocket and gRPC. gRPC uses HTTP/2 which is a major revision of the HTTP network protocol used by the World Wide Web. That's why, these are two protocols to be compared: WebSockets and HTTP/2.
BIDIRECTIONAL. Whereas HTTP relies on a client request to receive a response from the server for every exchange, WebSockets allow for full-duplex bidirectional communication. This enables the server to send real-time updates asynchronously, without requiring the client to submit a request each time.
Bidirectional streaming RPCThe server can choose to send back its initial metadata or wait for the client to start streaming messages. Client- and server-side stream processing is application specific. Since the two streams are independent, the client and server can read and write messages in any order.
In gRPC, we can have streaming with three functional call types: Server streaming RPC: The client sends a single request to the server and gets back several messages that it reads sequentially. Client streaming RPC: The client sends a sequence of messages to the server.
gRPC is not really the relevant part for comparison, it's that gRPC uses HTTP/2 which can certainly be compared to WebSockets.
https://www.infoq.com/articles/websocket-and-http2-coexist
This article outlines them quite well. Essentially, HTTP/2 is Client/Server with Server Push on the background, so you can make your request and simply stay on that connection listening for updates without the need for polling, for example.
Whilst WebSockets are not going away because of HTTP/2, they might not be considered necessary for use cases that center around "let me know when updates happen related to the thing I just did".
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