In this blog, I’m going to explore the modern method for data serialization: protocol buffers (usually referred to as Protobuf). A protocol buffer is a binary communication format designed by Google that allows us to serialize and deserialize structured data.

But wait, the above tasks can also be done by other formats such as JSON or XML, so why did Google choose to design a new communication format? As we all know, almost all big tech giants are majorly focused on high performance and optimized speed. Due to the tremendous popularity of microservices architecture system, it’s been very difficult to manage the communication between thousands of services using text-based communication format as services generate thousands of requests to each other, load a network, and require a lot of resources. This is why we need a fast way to serialize transferring compact data between services. In this scenario Protocol buffers can save us a lot of time, money, and resources.

It is important to note that, although JSON and Protobuf do the same job, these technologies were designed with different goals and approaches in mind.

Protocol buffers were designed to be faster than JSON & XML by removing many responsibilities performed by these formats and focusing solely on the ability to serialize and deserialize data as fast as possible. Another important optimization is regarding how much network bandwidth is being utilized by making the transmitted data as small as possible.

How are Protobuf’s faster than other communication formats?

Data transmitted during communication is in the form of binary which improves the speed of transmission compared to JSON’s string format.

Let’s take a look at the following example to get a clear understanding of this:

{
 "status":"success",
 "message":"found"
}

In the above JSON object, there are a total of 38 characters including spaces and characters like { } , "" : which don’t possess any kind of informational data. So finally we have 2 curly brackets, 8 quotation marks, 2 colons, and 1 comma which added up to 13 characters, and keywords of JSON object occupies a total space of 6+7 = 13 characters whereas the information value of JSON object occupies 7 +5= 12 characters.

After summing up the result we get the following information:

  • JSON object length: 38 bytes
  • Informational length: 12 bytes
  • Non-Informational length: 26 bytes [“WASTAGE”]

Image for post

#http2 #protobuf #grpc #microservices #protocol-buffers

Modern Data Serialization Method — Protocol Buffers
1.05 GEEK