← Lessons

quiz vs the machine

Platinum1780

Networking

Protocol Buffers

A compact binary format with a schema and field numbers for evolution.

5 min read · advanced · beat Platinum to climb

What protocol buffers are

Protocol buffers, often called protobuf, are a binary serialization format defined by a schema. You write a message definition, and a compiler generates code to encode and decode it in many languages.

Why binary and schema based

Compared to text formats like JSON, protobuf is smaller and faster to parse because fields are encoded by number, not by name.

  • Each field has a unique field number used on the wire.
  • Types and structure come from the shared schema.
  • The compiler produces typed classes for each language.

Schema evolution

The field number is the key to backward compatibility. You can add new fields with new numbers, and old readers simply ignore what they do not recognize. Removing a field means reserving its number so it is never reused. Most fields are optional on the wire, so a missing field decodes to a default rather than failing. These rules let independently deployed services upgrade their messages without breaking each other, which is why protobuf pairs naturally with gRPC.

Key idea

Protocol buffers encode data compactly by field number against a shared schema, enabling safe evolution across services.

Check yourself

Answer to earn rating on the learn ladder.

1. What identifies a field on the protobuf wire?

2. How do you keep old readers working when removing a field?

3. Why is protobuf typically smaller than JSON?