English 中文(简体)
Protobuf - Introduction
  • 时间:2024-09-17

Protobuf - Introduction


Previous Page Next Page  

Before we jump into Protocol Buffer, let us go over a brief background of Seriapzation which is what Protocol Buffer does.

What is Seriapzation and Deseriapzation?

Seriapzation is the process of converting an object (of any language) into bytes and storing them in persistent memory system. This memory system could be a file on the disk, messaging queue or a database. The major intention with seriapzation of object is that we can reuse the data and recreate the object on same or different machine. In deseriapzation, we convert the stored bytes back to an object.

Why do we need Seriapzation and Deseriapzation?

While there are a few other use-cases, the most basic and important one is that it provides a way to transfer object data over a network to a different service/machine etc. and then to recreate object for its further use. Transferring object data via API, database or messaging queue requires the object to be converted into bytes so that it can be sent over a network. And this is where seriapzation becomes important.

In microservice architecture, the apppcation is broken down into small services and these services communicate with each other via messaging queue and APIs. And all of this communication happens over a network which requires frequent conversion of object to bytes and back to objects. So, seriapzation and deseriapzation becomes very critical aspects when it comes to distributed environment.

Why Google Protobuf?

Google Protobuf performs the seriapzation and deseriapzation of the objects to bytes which can be transferred over the network. But there are some other pbraries and mechanisms to transfer data as well.

So, what makes Google Protobuf special? Here are some of its important features −

    Language independent − Multiple languages have protobuf pbrary, few famous ones being Java, Python, Go, etc. So, a Java object can be seriapzed into bytes from a Java program and can be deseriapzed to a a Python object.

    Efficient Data Compaction − In microservice environment, given that multiple communications take place over a network, it is critical that the data that we are sending is as succinct as possible. We need to avoid any superfluous information to ensure that the data is quickly transferred. Google Protobuf has that as one of the focus areas.

    Efficient seriapzation and deseriapzation − In microservice environment, given that multiple communications take place over a network, it is critical how fast can we seriapze and deseriapze. Google Protobuf ensures that it is as quick as possible in seriapzing and deseriapzing the data.

    Simple to use − Protobuf pbrary auto-generates seriapzation code (as we will see in the upcoming chapters), has a versioning scheme to ensure that the creator of data and the user of data can have separate versions of the seriapzation definition, etc.

Protobuf vs Others (XML/JSON/Java seriapzation)

Let s take a look how other ways to transfer data over a network stack up against Protobuf.

Feature Protobuf JSON XML
Language independent Yes Yes Yes
Seriapzed data size Least of three Less than XML Highest among the three
Human Readable No, as it uses separate encoding schema Yes, as it uses text based format Yes, as it uses text based format
Seriapzation speed Fastest among the three Faster than XML Slowest among the three
Data type support Richer than other two. Supports complex data types pke Any, one of etc. Supports basic data types Supports basic data types
Support for evolving schema Yes No No
Advertisements