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.

Pasted image 20230901091337.png

Because it supports multiple languages, the server and client can use different languages and use the generated code to talk to each other.

Pasted image 20230901091425.png

Example

  1. 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.
  2. gRPC sends the data over the network as a stream of HTTP 2

The rest of the flow happens as follows:

Pasted image 20230901091929.png

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.

Pasted image 20230901092232.png

Where would gRPC shines?

It's better to deal with gRPC for microservices communication.

For example:

Pasted image 20230901092343.png

Or native mobile phone.