Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON-based API over ZeroMQ

Tags:

json

zeromq

Most modern API's are built using JSON with request/response messaging over HTTP. Since ZeroMQ is over TCP, could JSON-based API's be built over ZeroMQ? If so, what would the advantages be? The use is

  1. developers writing apps for clients/devices communicating with one or more webservers, and

  2. webservers communicating with webservers.

like image 711
Henry Thornton Avatar asked Jan 11 '13 09:01

Henry Thornton


1 Answers

Yes, json-based API could be built on top of ZeroMQ instead of HTTP. It would require REQ/REP sockets. However, it doesn't seem to be a good choice.

The main advantage of JSON+HTTP approach is portability. JSON+HTTP is supported out of the box by virtually any programming environment, ZeroMQ is not supported so widely (no support in browser JS for example). Also, ZeroMQ is not so painless in setup, so service consumers probably won't be happy with that choice.

On the other hand, the main advantage of ZeroMQ is performance: it's great if you need to push many megabytes (or probably gigabytes) of data per second. JSON encoding/decoding is really fast, but the size matters too for this kind of tasks. Any binary serialization framework seems to be a better choice, there are plenty: protobuf, thrift, BSON, kryo, avro, etc.

So, I'd continue to use JSON+HTTP for APIs of web services: modern HTTP server tools provide excellent performance and scalability. And ZeroMQ is a great choice for communication within a controlled environment because of its concurrency features and well-defined usage patterns.

like image 68
Wildfire Avatar answered Nov 12 '22 15:11

Wildfire