Skip to content
BENIBIX Learn

Protocol Buffers (Protobuf)

Development📄 Files & FormatsData Formats

Also known as Protobuf, .proto File, Google Protocol Buffers

A compact way to send data as bytes. It is smaller and faster than JSON.

Think of it like

Think of it like a numbered order form. You write 1 for the name and 2 for the age, so it stays short.

Example

Two services in an online shop talk thousands of times a second. They send Protobuf, so each message is small and quick to read.

Why it matters

At high volume, smaller messages save time and money. It is also the format that gRPC sends.

Definition

Protocol Buffers is a format from Google for sending data as compact bytes. You first describe the data in a .proto file. A tool turns that file into code for your language. That code packs data into small bytes and unpacks it again. It works like JSON, but it is smaller and faster to read. The catch is that people cannot read the bytes.

Example code

protobuf
message Person {
  string name = 1;
  int32 age = 2;
}
Each field gets a type and a number. The numbers, not the names, go into the bytes.
The same record is 24 bytes as JSON and 8 bytes as Protobuf.

Common mistake

Changing a field's number after it is in use. Old messages then put their data in the wrong field.

Key takeaways

  1. 1
    Schema first. You describe the data in a .proto file.
  2. 2
    Made code. A tool writes the packing code for you.
  3. 3
    Small and fast. Bytes, not text people can read.

Compare

Learn it properly