Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between grpc and websocket? Which one is more suitable for bidirectional streaming connection?

I want to develop a client-server application in a bi-directional streaming manner.

what is more suitable technology for this, grpc or websocket?

like image 626
prashant sindhu Avatar asked Oct 24 '17 07:10

prashant sindhu


People also ask

Is gRPC same as 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.

Is WebSocket bidirectional?

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.

What is bidirectional streaming in gRPC?

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.

Is gRPC used for streaming?

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.


1 Answers

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".

like image 140
Phil Sturgeon Avatar answered Sep 22 '22 10:09

Phil Sturgeon