Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protocol Buffer vs Json - when to choose one over another

Can anyone explain when to use protocol buffer instead of JSON for micro-services architecture? And vice-versa? Both on synchronous and asynchronous communication.

like image 752
Kaidul Avatar asked Sep 19 '18 15:09

Kaidul


People also ask

When might it be useful to use JSON instead of Protobuf?

Both Protocol buffers and JSON are languages interoperable, but Protobuf are limited to subsets of programming language, whereas JSON is widely accepted. JSON contains the only message and not schema, whereas Protobuf not only has messages but also includes a set of rules and schemas to define these messages.

Is Protobuf more efficient than JSON?

JSON is usually easier to debug (the serialized format is human-readable) and easier to work with (no need to define message types, compile them, install additional libraries, etc.). Protobuf, on the other hand, usually compresses data better and has built-in protocol documentation via the schema.

Why should we use Protobuf?

The required , optional , and repeated keywords in Protocol Buffers definitions are extremely powerful. They allow you to encode, at the schema level, the shape of your data structure, and the implementation details of how classes work in each language are handled for you.


1 Answers

When to use JSON

  • You need or want data to be human readable
  • Data from the service is directly consumed by a web browser
  • Your server side application is written in JavaScript
  • You aren’t prepared to tie the data model to a schema
  • You don’t have the bandwidth to add another tool to your arsenal
  • The operational burden of running a different kind of network service is too great

Pros of ProtoBuf

  • Relatively smaller size
  • Guarantees type-safety
  • Prevents schema-violations
  • Gives you simple accessors
  • Fast serialization/deserialization
  • Backward compatibility

While we are at it, have you looked at flatbuffers?

Some of the aspects are covered here google protocol buffers vs json vs XML

Reference:

https://codeclimate.com/blog/choose-protocol-buffers/

https://codeburst.io/json-vs-protocol-buffers-vs-flatbuffers-a4247f8bda6f

like image 186
so-random-dude Avatar answered Sep 22 '22 09:09

so-random-dude