Grpc
Rewrite of RPC (Remote Procedure Call).
Use of Protocol Buffer to encode and send data by default. However it can support other format such as JSON but protocol buffer is better:
- gRPC supports binary encoding so it's much faster comparing to JSON
- Build based on support of HTTP 2 which provides high performance foundation — which allows multiple stream of messages over a long lived TCP (Transmission Control Protocol) connection
- gRPC is 5x time faster than json
gRPC used the Protocol Buffer file to generate the code so that the client can use this code to perform gRPC call.
Because it supports multiple languages, the server
and client
can use different languages and use the generated code to talk to each other.
Example
- gRPC client use gRPC code generation to generate a client stub which can be used to communicate with the gRPC server.
- gRPC encoded the data passed to this client stub in a Binary Encoding and send it to the low-level transport layer.
- gRPC sends the data over the network as a stream of HTTP 2
The rest of the flow happens as follows:
Why is it not being used by webclient / webserver.
gRPC relies on lower access to HTTP 2, which no browser currently support
It's possible to make a Reverse proxy for the web server to interact with gRPC. The technology is called gRPC web
However it's not fully compatible with gRPC which have all of the features from traditional gRPC. And it's slower.
Where would gRPC shines?
It's better to deal with gRPC for microservices communication.
For example:
Or native mobile phone.