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. The official documentation gives the same rule of thumb: once messages pass a megabyte each, consider another strategy. Protobuf was designed with small messages in mind.

An RPC framework can stop a message long before the format does. A default cap of 4 MB on incoming messages is common, and it stays until you raise it.

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. A message doesn't mark where it ends, so in a file or a raw stream each one needs its length written in front of it. A streaming RPC does that for you.

Schema limits

Schemas have limits too. Edition 2026 makes the compiler reject a message with more than 1500 fields or 1000 oneofs, a oneof with more than 1200 fields, and an enum with more than 1700 values. Generated code tends to break well before the wire format does, so these catch the problem in the schema instead.

A type that really needs to be larger can opt out by setting features.enforce_proto_limits to LEGACY_NO_EXPLICIT_LIMITS. The setting goes on the oversized message, oneof, or enum itself, because the feature can't be set for a whole file.

Nesting depth

Parsers also cap how deeply messages can nest. The C++ and Java runtimes stop at 100 levels by default, and Go stops at 10,000. A message nested deeper than the limit fails to parse. Recursive types are how real schemas get there: a tree whose nodes hold more nodes, or a deeply nested Value.

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.