Javascript to Elixir Message formats


What do people here use to communicate between Javascript and Elixir:

  • JSON?
  • MsgPack?
  • Erlang term format?
  • Something else?

Are there any best practices here?

For most of what I want to do, JSON is probably enough, but I wonder if MsgPack is better for events that are sent frequently, like a user typing in real time. I’m nowhere experience enough to setup benchmarks with a real web browser or something like hound, so I wonder if there are any benchmarks available.


I have been playing a little with MsgPack for a notification service that needs to be really conservative with bandwidth and “alot of” messages running through a Raspberry PI board.

I haven`t run any performance tests so I can’t, give you any numbers.
Most important for us was saving space.
And since every KB counts over thousands of devices we are able to save roughly 30 % on that costs.

However JSON is fast and good enough for 90 % of the use cases we have.

We use msgpax and its a wonderful library.
This was a bit of a rush job to get a prototype up and running fast I wish I had more knowledge on msgpack.
And I plan on doing some tests to get msgpack to speak to c++ just for fun.
I found [this] ( article some time ago and want to test it.


@Hoegbo are you connecting to the Raspberry Pi over websockets or is it more REST-like


Were using REST.


Does the advantage in transfer size still apply if you’re using gzip/brotli?


Not for us. The messages are not big enough to properly benefit from compression. Furthermore doing the compression on the device would kill battery life. The clients are 25 MHz mcu’s so processing power is an issue too.


Thanks for your input :slight_smile:


Geez, at this point I’d probably opt for flatbuffers or something to minimize the processing time and size needed on the data structure… o.O


If it were up to me, which it wasn’t, I’d have the system built completely different.
But for my part in the project which was the Raspberry Pi using Messagepack. it works wonders on that end.

My point was that Messagepack is a good compromise of performance vs size. and should be considered for the 5-10% odd times you need the performance improvement. JSON or gzipped JSON is what you should use for most things especially if your target is a browser.

Flatbuffers is new to me. I was looking at Cap’n’Proto to one day possibly replace my own code if needed.


I’ve used cap’n’proto, it’s good, but I’d pick flatbuffers over it nowadays. Flatbuffers has both a super-fast schema mode, and it has a very cap’n’proto-styled dynamic encoding mode as well that is also very fast, so you can support both styles at once (in different structures). Plus flatbuffers has windows support as well if ever needed.


Thanks everyone :slight_smile: I think I’ll go the MsgPack way, at least for now.