Protocol Buffers (Protobuf) is a free and open source cross-platform library used to serialize structured data. It is useful in developing programs to communicate with each other over a network or for storing data. The method involves an interface description language that describes the structure of some data and a program that generates source code from that description for generating or parsing a stream of bytes that represents the structured data.
We recommend you use Protobuf when:
You need fast serialisation/deserialisation
Type safety is important
Schema adherence is required
You want to reduce coding
Language interoperability is required
You want to use the latest shiny toy
How Do Protocol Buffers work?
Protocol buffer works through binary serialization. It encodes the data using the determined schema and sends the data.
The receiver decodes the data with the schema to get the message. Here, the message is encoded with a schema and stream it as a binary data to the receiver.
The receiver decodes the data with the same schema and get the message from the binary stream.
Simpler, faster, smaller in size.
RPC support: Server RPC interfaces can be declared as part of protocol files.
Structure validation: Having a predefined and larger structure, when compared to JSON, set of data types, messages serialized on Protobuf can be automatically validated by the code that is responsible to exchange them.
Non-human readability: JSON, as exchanged on text format and with simple structure, is easy to be read and analyzed by humans. This is not the case with a binary format. [There are now ways to make protobuf human readable too though. ]
Lesser resources and support: You won’t find that many resources (do not expect very detailed documentation, nor too many blog posts) about using and developing with Protobuf.
Smaller community: Probably the root cause of the first disadvantage. On Stack Overflow, for example, you will find roughly 1.500 questions marked with Protobuf tags. While JSON has more than 180 thousand questions on this same platform.
The Key Difference Between Protocol Buffer and JSON
Protocol is an efficient way of encoding data and was developed by google for serialization and de-serialization structured data
These are language independent and platform neural encoding mechanism
JSON is language interoperable JSON is another way of storing python objects into a disk so that later on it can be loaded without having the need to recreate the data again.
It is not just a message format, it also incorporates a set of rules to define and exchange messages
It is Simple a message format without having any schemas.
Protobuf languages are in binary format.
JSON messages are exchange in human readable text format
Protobuf currently limited to only few programming languages.
JSON supported by almost all the programming languages. JSON is language independent.
Protobuf schemas are associated with the data
JSON stores data in text format and doesn't have any schemas associated with it.
It is mostly useful for sending data between internal services
It is used in web applications where data exchange takes place between a browser and server.
Protobuf supports more data types than JSON
JSON is limited to certain python objects and it cannot serialized every python objects.
It is faster than JSON
JSON is faster than other serialization techniques like pickling.
The Tech Platform