Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON transfer vs Binary transfer

Tags:

rest

When it comes to computer/network all data are transferred as 0s and 1s. If so I don't understand what makes difference binary protocol than text protocol. I do understand when it comes image other transfer can happen on binary protocol as those bytes are not human readable. But during REST web service call binary transfer faster than JSON as we are transferring text only. Please refer if there is any link to understand in depth. Thanks!

like image 846
Sun Avatar asked Mar 04 '18 14:03

Sun


People also ask

Is JSON a binary format?

The name "BSON" is based on the term JSON and stands for "Binary JSON". It is a binary form for representing simple or complex data structures including associative arrays (also known as name-value pairs), integer indexed arrays, and a suite of fundamental scalar types.

Are binary formats more space efficient than JSON?

Although JSON is less verbose than XML, they both still use a lot of space compared to binary formats.

Which is better JSON or BSON?

The data in MongoDB is stored in a BSON format. JSON requires less space as compared to BSON. BSON requires more space as compared to JSON. It is comparatively less faster than BSON.

What is the difference between a JSON and BSON document?

BSON is nothing but Binary JSON i.e Binary JavaScript Object Notation. Unlike JSON, it is not in a readable format. It supports the embedding of documents and arrays within other documents and arrays. Like JSON, it is easy for machines to parse and generate.


1 Answers

You can find a great and extensive explanation of the advantages of binary protocols over text protocols (such as REST or XML) in the ProtoBuf documentation (https://developers.google.com/protocol-buffers/docs/overview) and the explanation of it's binary format (https://developers.google.com/protocol-buffers/docs/encoding).

At the risk of over simplifying, binary formats allow for a concise description of the data by sacrificing human readability. By "concise" I mean orders of magnitude smaller.

This is possible because TCP and UDP don't care about the payload. The payload is only important to the application, so therefore the app can define a specific purpose format to describe the data. Thus a single byte in the payload can have 256 interpretable meanings if you define it that way.

General purpose, human readable formats like REST and XML need to be interpreted by general purpose parsers. So their formatting adds bytes to differentiate between data elements, value labels, and general human readability. These extra bytes will be extensive and can easily exceed the size of the data itself.

In many cases the human readability is a preferable sacrifice, such as in simple client/server apps. But for high performance, massively scaled infrastructures (such as Google's search index) the overhead becomes a huge penalty to performance and a binary format is necessary.

like image 96
John Fricker Avatar answered Oct 29 '22 09:10

John Fricker