Search code examples
javagrpcproto3

gRPC and Protobuf - How and Where the Efficiency is Achieved as part of Building/Binding?


I am very new to gRPC and Protobuf (Java Binding). I tried to read the documentation and found the below diagram helpful (from protobuf official guide)

https://protobuf.dev/overview/#work

What I've understood so far:

  1. The message definitions (.proto files) are compiled into Java classes
  2. Those classes are eventually compiled into bytecodes and packed with JARs

But I am still struggling to understand how the optimisation actually works i.e. how does the bytecode become so small?


Solution

  • I believe you are missing the distinction between two things:

    • The size of the bytecode, the code generated to handle protocol buffers
    • The size of the messages after being encoded into bytes, the content sent over the network or stored on disk, the values of the types described in the proto files

    Protocol buffers are quite good at the second of these. They are not necessarily special at the first of these.