gRPC

  • free and open source framework developed by Google
  • it is part of CNCF (Cloud Native Computation Foundation) - like Docker and Kubernetes
  • It allows you to define REQUEST and RESPONSE for RPC (Remote Procedure Calls) and handles all the rest for you.
  • gRPC = HTTP/2 + Protobuf
  • pros:
    • Modern, fast and efficient
    • Built on HTTP/2
    • low latency, supports streaming, language independent
    • easy to plug in authentication, load balancing, logging and monitoring

RPC (Remote Procedure Call)

  • RPC feels like calling a function on the server code from a client code
  • gRPC is popular implementation of RPC
  • Advantage of RPC is that you don’t need to write communication logic again and again, it hides the complexity of API call
    • failures
    • retries
    • communication protocol
    • compression
    • streaming
  • In RPC world we need to generatestubs for each language
  • Stubs:
    • serialize/deserialize
    • convert methods/request types/response types to be used by RPC system
    • Stub Interface Definition Language is used to define the types in multiple languages. In gRPC we write .proto files for this

How to get started

  • You need to define the messages and services using Protocol Buffers
  • The rest of gRPC code is generated for you and you’ll have to provide implementation for it.
  • One .proto file works for over 12 programming languages (server and client) and allows you to use a framework that scales to millions of RPC per second.

Methods

  • gRPC supports four types of methods for client server interaction:
    • Unary - The traditional request-response communication
    • Client streaming - The client sends a series of messages to the server and the server returns a response after processing them.
    • Server streaming - The client needs to make a single request for the server to return a response with a stream of messages.
    • Bidirectional streaming - The client and server can communicate with each other asynchronously over a persistent session.

Calling

  • Define URL:
    • example: grpc.postman-echo.com
  • Define Method:
    • example: HelloService/SayHello
    • Each method is one of the types mentioned above
  • Define Message:
    • Message can be any format including json
    • It is converted into Protobuf format before sending/receiving
    • For example in the case of client streaming method, You can stream multiple messages and end the stream and then send

gRPC Flow

gRPC_flow

Permify

  • Permissions
  • Roles = Collection of Permissions
  • We need to store permissions and roles in some database/service
  • View Role
    • cart_view
    • product_view

API Call to Server (What Server does)

  • Receive request
  • Identify request token
  • using identity of the token, we send request to permify with permissions
    • permify authenticates the token
    • permify checks if the identity of the token has the permissions
    • permify returns response

Tasks

  • How to call permify via typescript client
  • How to configure grpc and ports in local and cloud
  • How proto files are setup, local setup grpc server + client
  • How to run permify project locally
    • How to run via make command
  • Latency calculate: local vs cloud
  • How to setup cache
  • How to do multi-instance (distributed instance)
  • Extended:
    • How to use WebSocket
    • What happens in metadata of gRPC
    • does grpc use https internally? is grpc a new protocol

Document

  • How to configure grpc and ports cloud
  • How to call permify via typescript client
  • Latency of REST API