Skip to content

Client - Server

gRPC

  • https://grpc.io/
  • Overview:
    • high performance, open source universal RPC framework
    • based on the idea of:
      • defining a service (= interface)
      • specifying the methods that can be called remotely with their parameters and return types
    • the server implements this interface and runs a gRPC server to handle client calls
    • the client has a stub (referred to as just a client in some languages) that provides the same methods as the server.
  • Architecture:
    • HTTP/2 based transport
    • different type of streaming:
      • unary: like a normal function call and sync answer
      • server stream: client sends request and server is streaming the response
      • client stream: client sends a streamed message, server is replying sync once all received
      • bi-directional: client and server stream independently
    • Use Protocol Buffer as default to serialize datas (as binary)
      • Provide interface definition syntax
      • Provide compiler protoc to create serializer/deserializer in languages of choice
    • Metadata:
      • is information about a particular RPC call
      • key/value pair
      • gRPC lets the client provide information with the call to the server and vice versa
    • Channel:
      • provides a connection to a gRPC server on a specified host and port
      • used when creating a client stub
      • has state, including connected and idle
  • gRPC vs JSON REST:

    • https://docs.microsoft.com/en-us/aspnet/core/grpc/comparison?view=aspnetcore-5.0
    • comparison:

       Feature  gRPC  JSON HTTP
      Interface   .proto file  No or optional
      L7 protocol   HTTP/2  HTTP
      Payload   ProtoBuf serialized   JSON
      Schema   Yes  No
      Streaming   client, server, bi-dir  client, server
      Browser support   through grpc-web  native
      Security   TLS  TLS
      Code generation   Yes, stub  through 3rd part.  
    • deadline:

      • gRPC allows clients to specify how long they are willing to wait for an RPC to complete.
      • The deadline is sent to the server
      • The server can decide what action to take if it exceeds the deadline