Protocol Buffer vs Json - when to choose one over another

Kaidul picture Kaidul · Sep 19, 2018 · Viewed 12.1k times · Source

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

Answer

so-random-dude picture so-random-dude · Sep 20, 2018

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