1 of 18

gRPC

Looking for magic 🪄

2 of 18

gRPC Remote Procedure Call

or Generic Remote Procedure Call

or Golden Retriever PanCakes [1]

It’s an RPC framework developed by Google

But no one knows what the G stands for, it’s a mystery.

[1] https://www.youtube.com/watch?v=njC24ts24Pg (YT @grpcio)

3 of 18

What is RPC?

4 of 18

Using HTTP as transport

5 of 18

IDL - Interface description language

Protocol Buffers is many things:

  • IDL
  • extensible compiler
  • encoding format
    • binary
    • JSON

6 of 18

Generated code

7 of 18

Why care about the protocol?

… if it just works?

  • Google Cloud Pub/Sub; gRPC
  • Google Cloud BigQuery; gRPC + Avro/Arrow for data
  • Apple APNs († 2021); binary over TCP
  • Apache XYZ; Apache Thrift
  • AWS; Smithy/JSON
  • Salesforce or SAP; SOAP
  • PostgreSQL; PostgreSQL wire protocol v3.2

8 of 18

gRPC works

… until it doesn’t

  • gRPC doesn’t work with browsers
    • https://github.com/grpc/grpc/issues/2786
    • gRPC-web: supports only unary requests or server-side streaming
  • HTTP/2 lives on one TCP connection, therefore it needs L7 load balancing

9 of 18

Trailer headers

Part of HTTP/2 specification, allowing sending extra info after body

Unsupported by any browser

Crucial feature for gRPC

10 of 18

gRPC Status

HTTP/2 response is always OK,�200 OK.

New numeric table to learn:�https://grpc.io/docs/guides/status-codes/

Lucky 13 is new 500

11 of 18

gRPC Request

Always POST

URL defines package, service and called method

encoding agnostic

5 byte prefix:

  • 1 byte compression flag
  • 4 bytes message size

12 of 18

gRPC Response

13 of 18

Shit hits the fan

Number and string,

can you handle it?

14 of 18

gOOGLE RPC Status

15 of 18

Protocol Buffers briefly

serialization data format for structured format

primary binary format, not self-describing

alternatively, canonical JSON format, ProtoJSON

Defined in .proto files, extendible IDL

Code generated by protoc

https://protobuf.dev/programming-guides/encoding/

16 of 18

Have you noticed any magic?

gRPC summary:

  • HTTP/2 POST
  • always 200 OK
  • URL defines method
  • length prefixed messages
  • trailer header status

17 of 18

🎩 The magic is HTTP/2 🎩

18 of 18