Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using BSON on client with JavaScript

For a financial system, I need to use a light-weight and fast protocol for transferring data from server to client with a Pushing Server (e.g. Socket.IO)

As you know, Packing and Unpacking with BSON also takes more time than using native JSON and maybe becomes a bottleneck itself.

I want to know, is this correct approach to use BSON instead of JSON for transferring data in order to reduce the size of messages?

like image 419
Afshin Mehrabani Avatar asked Mar 07 '26 11:03

Afshin Mehrabani


1 Answers

I want to know, is this correct approach to use BSON instead of JSON for transferring data in order to reduce the size of messages?

It depends on the application. If it's a browser-based application, then the answer is no. Mainly because browser-based javascript does not (yet) have the ability to work with binary data. There are proposals like typed arrays that can sort-of do it if really necessary but even the specification for that is considered merely "draft" for now. Not to mention the fact that IE doesn't support it.

For browser based applications the standard method to reduce size of packets is to use compression like gzip. This can be configured on your server or it can be done in your web app.

For non-browser based app the answer is it depends. Projects like MongoDB has had great success with BSON. On the other hand the web as a whole have been running well with just JSON+compression. The best answer is for you to benchmark it yourself and see if it makes sense in your case.

like image 137
slebetman Avatar answered Mar 09 '26 00:03

slebetman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!