4

I tried reading Protobuf docs, but couldn't imagine many usecases it can be used. I would like to know some real-world performance improvement usecases of protocol buffer . Thanks

Sagar
  • 5,315
  • 6
  • 37
  • 66

2 Answers2

8

Protocol buffers is a serialization library, so the answer to that is basically the same as to the question:

When would I want to serialize / deserialize data?

That could be any scenario involving persistence (disk, blobs in a database, etc), transfer (sockets, files, etc), or simply in-memory storage (snapshots, memento, deep-clone). The fact that protobuf is version-tolerant and cross-platform means that it can work for both homogeneous and heterogeneous setups - as indeed can various other serialization formats. Being terse (small) it may be particularly useful when bandwidth is at a premium (which is "always" on busy systems), and being a binary (rather than text) protocol, it is noticeably cheaper to process - so good for reducing CPU overhead. Beyond that: this is an open-ended question limited only by your imagination.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • SO, why should we use JSON/XML over Protobuf? Shouldn't we be always using protobuf/bson for that matter? – Sagar Apr 08 '13 at 14:20
  • @Kaunteya JSON is great for browser support. XML / json have human readability / editability, which is nice in many scenarios. XML has interesting tooling by way of xslt, xsd, sax, etc. The interesting thing to remember is that you don't have to limit yourself to one and only one :) – Marc Gravell Apr 08 '13 at 18:22
6

It's going to be more CPU and network efficient than something like Json, so whenever you know what'd you be sending, and need to send a lot of it, it's probably a win.

Tyler Eaves
  • 12,879
  • 1
  • 32
  • 39
  • Tyler Thanks.. could you please give me an example you might have come across before? That would help more in understanding exact use if it. – Sagar Apr 08 '13 at 13:59
  • @Kaunteya have you ever written any kind of data storage code? how about any kind of message-passing code? socket code? anything like that? – Marc Gravell Apr 08 '13 at 13:59
  • @Kaunteya or to pick another example: have you ever used xml? json? the answer to "when might I need something that does serialization?" would be the same question as it would to those tools. – Marc Gravell Apr 08 '13 at 14:01