What is gRPC?
gRPC is a google-made open source cutting-edge framework that can use in any language.
RPC (Remote Procedure Call) is a communication technology that letting other process using the function or procedure at the their own place without any extra address allocation.
To explain, when we decide to use the MSA(Micro Service Architecture), many different language and framework is needed to be developed in the same time.
But RPC make us free from the language to develop on our product since it is letting us invoke the remote procedure that we need.
Using gRPC make it easy to create distribution application and service than before. This is becuase we can invoke remote application's method like local method.
gRPC have a same idea as RPC system that define the services and create the methods that has parameters and return.
gRPC - HTTP/2
gRPC is now using HTTP/2. Let's compare what's changed from HTTP/1.
HOL Blocking Problem
The pair of request and response from HTTP/1 always follow the order and are done synchronously.
To be more specific, when we receive three images on one TCP connection, the HTTP request will look like the following:
|---a.png---| |---b.png---| |---c.png---|
After one request is done and the response is received, the next request is sent. This means if the previous request is still in progress, the next request cannot be sent.
If the request for a.png
is delayed, the total communication time becomes slow even if b.png
and c.png
are processed quickly:
|------------a.png------------| |-b.png-| |---c.png---|
This is the HOL Blocking problem from HTTP/1.1. Although HTTP/1.1 introduced pipelining to conditionally send requests first, it still processes responses in the order they were sent, which does not effectively address the issue when a.png
is being processed.
In contrast, HTTP/2 allows requests to be sent in parallel. Each request and response for a.png
, b.png
, and c.png
can be processed simultaneously. So while a.png
is taking a long time, b.png
and c.png
can receive their responses first and be displayed:
|------------a.png------------| |-b.png-| |---c.png---|
This eliminates the HOL Blocking issue present in HTTP/1.1. Additionally, HTTP/2 offers features like 'Flow Control' and 'Priority,' which allow for better management of connection details and prioritization of important resources.
gRPC Stub
In gRPC, a stub is a code component that serves as an intermediary between the client and the server. Stubs are automatically generated based on the service definitions written in Protocol Buffers (protobuf). While stubs are used on the client side, skeletons (often referred to as service implementations) are used on the server side.
Since the server and client operate in different address spaces, it's essential to convert the parameters used in function calls. Without this conversion, pointers to memory parameters might reference incorrect data.
gRPC Stub
Client stubs are generated on the client side and provide a simplified interface for clients to make remote method calls. Stubs handle the serialization of parameters used in the function call (called 'marshalling') and convert the results received from the server.
gRPC Server
On the server side, the gRPC server manages the conversion of parameters sent by the client and the conversion of the function execution results (called 'unmarshalling').