Stubs & Skeletons:
[Stubs] :
- Generated on RPC client side
- Handles:
- Serialization of data,
- and Deserialization of responses.
- Triggers Skeletons
[Skeletons (Service Implementations)] :
- Method invoked on RPC server side
- Handles:
- Deserialization of requests
- Serialization of responses
- Responds to Subs
Steps (ref: Diagram as example)
Client Side [1] A REST call is made from the client (JSON usually)
[2-4]
- The order service (gRPC client) receives the REST call, transforms it, and
- Makes an RPC call to the payment service. gRPC encodes the client stub into a binary (protobuf)
- Format and sends it to the low-level transport layer.
[5]
- gRPC sends the packets over the network via [HTTP2].
Because of binary encoding and network optimizations, gRPC 5X faster than JSON.
Server side [6-8]
- The payment service (gRPC server) receives the packets from the network, decodes them, and invokes the server application.
[9 - 11]
- The result is returned from the server application, and gets encoded and sent to the transport layer.