markdown guide
 

There is no doubt it's faster, but the question is ...should I compare it with JSON? JSON can have any schema you want, it can be dynamic and it's easy to modify.
if the consumer app is a javascript based app it can make assumptions about the data structure or even extract the schema etc...whereas in protobufs you need a predefined schema, which you cannot carry with you and you need to share it with other consumer services beforehand.

 

Is it faster? Almost always, there's less protocol overhead, and the encoding and decoding is almost always less complex than for JSON.

The thing is though, does that actually matter? Unless you're sending pretty significant amounts of data, that efficiency difference is not likely to matter much for your use case, and JSON is generally easier to work with in most cases.

Personally, I prefer YAML over both unless efficiency really matters, because:

  • The short-form representation of YAML is marginally more efficient than JSON (it needs fewer quotation marks).
  • The long-form representation of YAML is easier for most people to read than JSON, making it a bit easier to debug.
  • YAML still supports custom data type representations like protobufs do.
 

Between the two, I prefer the flexibility of JSON and not having to maintain separate schemas and generate language bindings like many of the Protobuf libraries require. If speed or size of the data transfer becomes an issue, I like MessagePack. It’s another binary serialization format like Protobuf, but it’s flexible like JSON and doesn’t require schemas like Protobufs do. It’s also similarly size efficient as Protobufs, and can be extended to support custom types more easily than either Protobufs or JSON in my opinion. 99% of the time JSON is perfect, but a realtime low-latency application like chat or gaming would be a great use case for Protobufs or MessagePack.

Classic DEV Post from Apr 3

Workspace Wednesday: Show off your desk/computer setup!

Let’s share pics of everybody’s setups. Feel free to add details about your ha...

Oyetoke Toby profile image
Just a software engineer trying to make ends meet. My passion for Python and JavaScript is nothing to compare.

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️