Skip to content

Maximum size

A Protobuf message can't be larger than 2 GiB. The wire format could describe bigger lengths, since length prefixes are varints, but the official implementations track sizes as 32-bit signed integers. A standard parser that hits a payload past it throws an overflow error and refuses to read it, so treat the limit as fixed rather than a setting you can raise.

Practical sizes

In practice, keep messages under 1 MB, even though the official recommendation only asks for a few megabytes. Protobuf was designed with small messages in mind.

Past 10 MB, parsing uses a noticeable amount of CPU and memory. To move large datasets, chunk the data into a stream of smaller messages.

Whole-message parsing

The generated API parses a whole message and builds a complete object graph in memory before returning it. The parser can read from a stream, and some runtimes decode parts lazily, but you still get the message as one unit. Plan for the entire message to be in memory at once.

That in-memory copy is usually bigger than the wire bytes. Pointers, object overhead, and padding in your data structures can push memory usage to several times the size of the original payload. Most serialization formats behave the same way.

Further Reading

Next

Descriptors

A schema compiled into Protobuf data. Descriptors are what reflection, dynamic decoding, and breaking-change detection read.