What are Protocol Buffers AKA Protobuf?

Suyoj Man Tamrakar
3 min readJan 3, 2022

Protocol buffers, also known as protobuf, are internally developed by Google to provide a better method of data serialization and deserialization compared to XML.

Google developed protocol buffers to make data serialization and deserialization simpler, smaller, faster, and more maintainable than JSON, XML, etc.

Protobuf is used in combination with HTTP and RPCs (Remote Procedure Calls) for local and remote client-server communication — to describe the interfaces required here. The protocol composition is also called gRPC.

The definition of data to be serialized is written in configuration files called proto files with the extension .proto. These files will contain the configuration known as messages. Protocol buffer data is structured as messages, where each message is a small logical record of information containing a series of name-value pairs called fields.

What are the benefits of Google’s Protocol Buffers?

When developing Protobuf, Google placed emphasis on two factors: Simplicity and performance. At the time of development, the format — as already mentioned, initially used internally at Google — was to replace the similar XML format. Today it is also in competition with other solutions such as JSON(P) or FlatBuffers. As Protocol Buffers are still the better choice for many projects, an analysis makes the characteristics and strengths of this structuring method clear:

  1. Binary transfer format

The data is transmitted as binary. This improves the speed of transmission more than raw string because it takes less space and bandwidth. Since the data is compressed, the CPU usage will also be less.

2. Backward and forward compatibility

The implementation of Protobuf spares the annoying execution of version checks, which is usually associated with “ugly” code. In order to maintain backward compatibility with older versions or forward compatibility with new versions, Protocol Buffers uses numbered fields that serve as reference points for accessing services. This means you do not always have to adapt the entire code in order to publish new features and functions.

3. Separation of context And data

In JSON and XML, the data and context aren’t separate — whereas in Protobuf, it is separate.

4. Validation and extensibility

The definitions of the required, optional, and repeated keywords in protocol buffers are extremely powerful. They allow you to encode at the schema level.

5. Language interoperability

We can implement protocol buffers in a variety of languages. They make interoperability between polyglot applications in your architecture much simpler.

SYNTAX :

message person {
required string name = 1;
optional int32 Age = 2;
repeated string location = 3;
}

Conclusion

We’ve seen that protocol buffers are designed to be more efficient and faster than conventional data-transmission formats like JSON or XML. The compression of data can increase the speed and reduce CPU usage.

I can’t claim that Protobuf is an easy replacement for JSON, but it solves many issues of JSON, especially when working with microservice architecture.

One trade-off is that the readability of data is significantly reduced. This isn’t a big demerit when compared to the merits.

The speed comparison of JSON versus Protobuf is already available. It’s a growing technology, and I recommend everyone check out the official documentation and repository.

--

--