Why Google protobuf?

Why Google protobuf?

After reading of first google protobuf article, I received few queries like why and when to use Google protobuf? Already JSON fulfill all my need then why to switch Google protobuf? Which are the languages support Google protobuf? Does front-end support it? So I decided to answer them in a small article.

Why to use Google Protocol buffer?

  1. When you pass the data in JSON format, you are not able to validate the schema of that data. For data validation you need to apply some logic after receiving data. Protobuf allow you to use some keyword to do it like required, optional, repeated, and data types which is validating the response in the transfer or producer level only.
  2. JSON is the key, value pair. So if provider or producer of data change the key in the response then you also need to change the key in all consumer of that data. But in protocol buffer it doesn't matter because your schema is fix.
  3. If you always need to validate the all required data is present only in required format or not in the response.
  4. Using JSON your response comes in sorted order of keys. You can not able to decide the order of keys but in protobuf you can do it.
  5. Lastly I say "Performance".

When JSON is best choice over the Google Protobuf?

  1. When you don't know about the response schema you should go with JSON.
  2. JSON is more human readable to edit or modify data.
  3. If response directly consumed by browsers instead of any other technology then go with JSON because browser have good support of JSON.
  4. This is personal opinion, If you are using Javascript framework in the back-end then go with JSON. In this case JSON don't need much extra effort to convert into schema or model.
  5. If performance not a great matter to your project.

Which technologies support Google protobuf?

As per my knowledge following technologies support the Google protobuf. If I miss anything then please feel free to add this.

  1. Java
  2. Go
  3. Node
  4. Clojure
  5. Scala
  6. C++
  7. C#
  8. Dart
  9. Python

Does front-end technologies support it?

The answer of this question is "YES".

I tried this to use with the AngularJS by making small changes in service.

Change the response type of your http service call as

responseType: "arraybuffer"

Install the protobuf.js in the front-end to decode and encode the data.

Pankaj Saboo

Senior Lead Software Engineer at John Deere

6 年

Krishna P.?I hope this will answer your queries.

要查看或添加评论,请登录

Pankaj Saboo的更多文章

  • Transaction Management in MongoDB

    Transaction Management in MongoDB

    As I am using MongoDB since last 3 years in many environment and for many applications which is ranging from small…

    8 条评论
  • Cross-platform use of Google Protobuf

    Cross-platform use of Google Protobuf

    Recently got chance to work with Google protocol Buffer(mostly called as Google Protobuf). This is an one of the simple…

    2 条评论

社区洞察

其他会员也浏览了